Teddy* Posted November 6, 2009 Share Posted November 6, 2009 Hi i just installed vb 2008 express edition and i am making a program to change the logon background for personal use. anyway everything is working fine.... but there is one more thing... my friends want to use the program but it is not perfectly coded and i dont want to damage there computers so i need to check two things before the program starts 1-IsRunUnderWindows7() to see if the program is runing under windows 7. 2-IsRunAsAdmin() to see if the program is run with admin privilege. If anyone know how to do any of these to checks it would be grate Thanks Link to comment Share on other sites More sharing options...
0 BGM Posted November 6, 2009 Share Posted November 6, 2009 (edited) Hi, something like... (in c#) private void button1_Click(object sender, EventArgs e) { OperatingSystem os = Environment.OSVersion; if (os.Version.Major == 6 && os.Version.Minor == 1) { // Windows7 } } interestingly, if minor version is 0, then you are on Vista, windows 7 isn't really v7 :D for the other part.. this should work to test if a local user has a role of admin.. private void button2_Click(object sender, EventArgs e) { System.Security.Principal.WindowsIdentity u = System.Security.Principal.WindowsIdentity.GetCurrent(); System.Security.Principal.WindowsPrincipal p = new System.Security.Principal.WindowsPrincipal(u); MessageBox.Show("local admin status " + p.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator).ToString()); } i don't think this will work if you are logged on as a domain user, that is in the local admin group... i'll have a think about that one. Edited November 6, 2009 by BGM Link to comment Share on other sites More sharing options...
0 Teddy* Posted November 6, 2009 Author Share Posted November 6, 2009 Thanks for the help i'll test it later because i dont have time now... Thanks again Link to comment Share on other sites More sharing options...
0 Vorenus Posted November 6, 2009 Share Posted November 6, 2009 I wrote about this a week or so ago: Shield icons, UAC, and process elevation in .NET on Windows 2000, XP, Vista, and 7 In VB.NET it looks something like this: <DllImport("shell32.dll", EntryPoint:="#680")> Public Shared Function IsUserAnAdmin() As Boolean End Function Link to comment Share on other sites More sharing options...
Question
Teddy*
Hi i just installed vb 2008 express edition and i am making a program to change the logon background for personal use.
anyway everything is working fine....
but there is one more thing...
my friends want to use the program but it is not perfectly coded and i dont want to damage there computers
so i need to check two things before the program starts
1-IsRunUnderWindows7() to see if the program is runing under windows 7.
2-IsRunAsAdmin() to see if the program is run with admin privilege.
If anyone know how to do any of these to checks it would be grate
Thanks
Link to comment
Share on other sites
3 answers to this question
Recommended Posts