Skip to content

Commit

Permalink
b2s tools should not allow to be run as admin #75
Browse files Browse the repository at this point in the history
  • Loading branch information
JockeJarre committed Dec 23, 2023
1 parent b366324 commit bfd7f4d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
14 changes: 13 additions & 1 deletion B2SWindowPunch/B2SWindowPunch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Text.RegularExpressions;
using System.ComponentModel;
using System.Drawing;
using System.Security.Principal;
using System.Windows.Forms;
using Microsoft.Win32;

Expand Down Expand Up @@ -74,9 +75,20 @@ public class Options
public string cutter { get; set; }

}

private static bool IsAdmin()
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
private static int Main(string[] args)
{
if (IsAdmin())
{
PrintUsage();
Console.WriteLine("You should not start B2SWindowPunch as Administrator!");
return 1;
}
string[] cargs = Environment.GetCommandLineArgs();
Options inputOptions = new Options();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Security.Principal
Imports System.Windows.Forms
Imports Microsoft.Win32
Imports MessageBox = System.Windows.MessageBox

Module B2S_ScreenResIdentifier
Sub Main()
If IsAdmin() Then
MessageBox.Show("You should not start this as Administrator!", My.Resources.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If

Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New formPlayfield())
End Sub
Private Function IsAdmin() As Boolean
Dim identity As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As New WindowsPrincipal(identity)
Return principal.IsInRole(WindowsBuiltInRole.Administrator)
End Function
End Module
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
Imports System
Imports System.Drawing
Imports System.IO
Imports System.Security.Principal
Imports System.Windows.Forms
Imports Microsoft.Win32

Module B2SBackglassServerEXE
Sub Main()
If IsAdmin() Then
MessageBox.Show("You should not start this as Administrator!", My.Resources.AppTitle, MessageBoxButtons.OK, MessageBoxIcon.Stop)
Exit Sub
End If
Application.EnableVisualStyles()
Application.SetCompatibleTextRenderingDefault(False)
Application.Run(New formBackglass())
End Sub
Private Function IsAdmin() As Boolean
Dim identity As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As New WindowsPrincipal(identity)
Return principal.IsInRole(WindowsBuiltInRole.Administrator)
End Function
End Module
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Imports Microsoft.Win32
Imports System.IO
Imports System.Security.Principal

Public Class formBackglassServerRegApp


Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
If Not IsAdmin() Then
MessageBox.Show("You have to start this app as Administrator!", My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Stop)
End If

Dim CommandSilent As Boolean = False

If My.Application.CommandLineArgs.Count > 0 Then
CommandSilent = InStr(My.Application.CommandLineArgs(0).ToString().ToLower(), "silent", CompareMethod.Text) > 0
End If
Expand Down Expand Up @@ -168,7 +171,11 @@ Public Class formBackglassServerRegApp
End

End Sub

Private Function IsAdmin() As Boolean
Dim identity As WindowsIdentity = WindowsIdentity.GetCurrent()
Dim principal As New WindowsPrincipal(identity)
Return principal.IsInRole(WindowsBuiltInRole.Administrator)
End Function
Private Function CheckB2SServer(ByVal showmessages As Boolean) As Boolean

'Dim identity = WindowsIdentity.GetCurrent()
Expand Down

0 comments on commit bfd7f4d

Please sign in to comment.