Vbscript for SCCM to push
I have a VBScript to push by SCCM, but always failed. Hope you will help me to solve the problem. Thanks!
The script is below:
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set oUIResManager = createobject("UIResource.UIResourceMgr")
Set oCache = oUIResManager.GetCacheInfo()
strpath = oCache.Location
strWinFolder = oShell.ExpandEnvironmentStrings("%WINDIR%")
strCurPath = oFSO.GetAbsolutePathName(".")& "\"
strfile = strWinFolder+"\SysWOW64"
if oFSO.FileExists(strfile) then
dstPOL = strWinFolder+"\Sysnative\GroupPolicy\Machine\"+"registry.pol"
else dstPOL = strWinFolder+"\System32\GroupPolicy\Machine\"+"registry.pol"
end if
srcPOL = strCurPath+"registry.pol"
oFSO.copyfile srcPOL, dstPOL, True
strCMD = "cscript.exe "+strpath+"\***\ApplyPolicy.vbs"
set oExec = oShell.exec (strCMD)
I have tested on my machine and others not by SCCM, it is successful. But once it is pushed by SCCM, nothing happed. So I wonder whether there is something conflict with SCCM. Thanks!
July 24th, 2012 1:27am
Hi,
line oFSO.copyfile
srcPOL, dstPOL, True
srcPOL seems not defined in your script
Julien
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2012 3:57am
Hi, it's defined here:
srcPOL = strCurPath+"registry.pol"
July 24th, 2012 4:05am
Yes I dropped the line :)
In this line
strCMD = "cscript.exe "+strpath+"\***\ApplyPolicy.vbs"
\***\ is your packageID I guess?
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2012 4:10am
yes so do you have any idea about why it didn't work from SCCM, thanks!
July 24th, 2012 4:59am
How have you tested this on other machine with out SCCM? This script will not execute unless SCCM is present. Set oUIResManager = createobject("UIResource.UIResourceMgr").
Well Since you can't see what is happening to the script during execution you may want to create a log. Give this a shot and see if it helps.
On Error Resume Next
Set oShell = CreateObject("Wscript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
'Create Log File
Set logfile = oFSO.CreateTextFile("ScriptLog.txt", True)
Set oUIResManager = createobject("UIResource.UIResourceMgr")
Set oCache = oUIResManager.GetCacheInfo()
strpath = oCache.Location
if Err.number <> 0 Then
logfile.WriteLine("Error: " & err.number & Space(1) & err.Description & vbNewLine)
End if
'Write To Log
logfile.WriteLine("Cache Locations: " & strpath)
strWinFolder = oShell.ExpandEnvironmentStrings("%WINDIR%")
strCurPath = oFSO.GetAbsolutePathName(".")& "\"
strfile = strWinFolder+"\SysWOW64"
if oFSO.FileExists(strfile) then
dstPOL = strWinFolder+"\Sysnative\GroupPolicy\Machine\"+"registry.pol"
else dstPOL = strWinFolder+"\System32\GroupPolicy\Machine\"+"registry.pol"
end if
srcPOL = strCurPath+"registry.pol"
logfile.WriteLine(vbNewLine &_
"WinDir: " & strWinFolder & vbNewLine &_
"CurrentPath: " & strCurPath & vbNewLine &_
"StrFile: " & strfile & vbNewLine &_
"Local Policy Destination: " & dstPOL & vbNewLine &_
"Local Policy Source: " & srcPOL)
oFSO.copyfile srcPOL, dstPOL, True
'Check Copy
if Err.number <> 0 Then
logfile.WriteLine(vbNewLine & "Error: " & err.number & Space(1) & err.Description)
End if
strCMD = "cscript.exe "+strpath+"\***\ApplyPolicy.vbs"
set oExec = oShell.exec (strCMD)
logfile.WriteLine(vbNewLine & "External Script OutPut")
Do While Not oExec.StdOut.AtEndOfStream
logfile.WriteLine(oExec.StdOut.ReadLine())
Loop
Free Windows Admin Tool Kit Click here and download it now
July 24th, 2012 8:39am