Jump to content

Need help for logon script , Urgent.


Recommended Posts

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 XP

objShell.Run "gpupdate /force", 1, True

;But i don't know how... :(

;This will for 2000

objShell.Run "SECEDIT /REFRESHPOLICY USER_POLICY /ENFORCE", 1, True

Edited by justhink
Link to comment
Share on other sites


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.Version
Next

For XP for example, it will give this output:

Microsoft Windows XP Professional
5.1.2600

You 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.

Link to comment
Share on other sites

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.Version
Next

For XP for example, it will give this output:

Microsoft Windows XP Professional
5.1.2600

You 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 Next

Set 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, True

Next

objShell.Run "calc.exe", 1, True

This 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..

Link to comment
Share on other sites

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 Select
Next

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

This 1 works fine but after few little modification, but thank you..

Option Explicit
Dim objItem, colItems, objWMIService, strComputer, objShell
strComputer = "."
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 If
Next

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...