justhink Posted July 10, 2008 Posted July 10, 2008 (edited) Nedd to run a vbs script on logon, which update group policy, but there are few clients are using 2000 professional, so GPUPDATE won't use, hav to use SECEDIT so, can some 1 tell me how to determin OS via VBS so it can run GPEDIT on XP clients and SECEDIT on 2000 clients,Please help me, urgent,Script is >Set objShell = CreateObject("WScript.Shell");this will run on XPobjShell.Run "gpupdate /force", 1, True;But i don't know how... ;This will for 2000objShell.Run "SECEDIT /REFRESHPOLICY USER_POLICY /ENFORCE", 1, True Edited July 10, 2008 by justhink
bennebiest Posted July 10, 2008 Posted July 10, 2008 To determine the Windows version:strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each OS In colSettings Wscript.Echo OS.Caption WScript.Echo OS.VersionNextFor XP for example, it will give this output:Microsoft Windows XP Professional5.1.2600You can put the output in a variable and make a Select Case to execute te gpupdate or secedit, dependig on the Windows version.Happy coding.
justhink Posted July 10, 2008 Author Posted July 10, 2008 To determine the Windows version:strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each OS In colSettings Wscript.Echo OS.Caption WScript.Echo OS.VersionNextFor XP for example, it will give this output:Microsoft Windows XP Professional5.1.2600You can put the output in a variable and make a Select Case to execute te gpupdate or secedit, dependig on the Windows version.Happy coding.I can do this much..On Error Resume NextSet objShell = CreateObject("WScript.Shell")strComputer = "."Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)For Each objItem in colItems If InStr(1,objItem.Caption,"Server") Then objShell.Run "notepad.exe", 1, TrueNextobjShell.Run "calc.exe", 1, TrueThis script can detect and run specific file for on specific os, there is a problem, when i run it on Windows 2003 it's opening both notepad and calculator, but on XP it opens calculator only, so how do i add stop execution after it open notepad on 2003..Thanks..
bennebiest Posted July 10, 2008 Posted July 10, 2008 Try this one:strComputer = "."Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")Set colSettings = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem")For Each OS In colSettings 'Wscript.Echo OS.Caption 'WScript.Echo OS.Version strOS = OS.Caption WScript.Echo strOS Select Case strOS Case "Microsoft Windows XP Professional" WScript.Echo "XP" 'paste your gpupdate code Case "Microsoft Windows 2000 Professional" WScript.Echo "2000" 'paste your secedit code End SelectNext
gunsmokingman Posted July 10, 2008 Posted July 10, 2008 Try this you will have to add the code you want it to run.Option Explicit Dim Act :Set Act = CreateObject("WScript.Shell") Dim objItem, colItems, objWMIService, strComputer strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48) For Each objItem in colItems If InStr(objItem.Caption,"2000") Then WScript.Echo objItem.Caption End If If InStr(objItem.Caption,"2003") Then WScript.Echo objItem.Caption End If If InStr(LCase(objItem.Caption),Lcase("XP")) Then WScript.Echo objItem.Caption End If Next
justhink Posted July 11, 2008 Author Posted July 11, 2008 Try this you will have to add the code you want it to run.Option Explicit Dim Act :Set Act = CreateObject("WScript.Shell") Dim objItem, colItems, objWMIService, strComputer strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48) For Each objItem in colItems If InStr(objItem.Caption,"2000") Then WScript.Echo objItem.Caption End If If InStr(objItem.Caption,"2003") Then WScript.Echo objItem.Caption End If If InStr(LCase(objItem.Caption),Lcase("XP")) Then WScript.Echo objItem.Caption End If NextThis 1 works fine but after few little modification, but thank you..Option ExplicitDim objItem, colItems, objWMIService, strComputer, objShellstrComputer = "."Set objShell = CreateObject("WScript.Shell")Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)For Each objItem in colItems If InStr(objItem.Caption,"2000") Then objShell.Run "secedit /refreshpolicy", 1, True End If If InStr(LCase(objItem.Caption),Lcase("XP")) Then objShell.Run "gpupdate", 1, True End IfNext
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now