Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a VBS script that builds an Outlook Email signature and saves it to the user's machine. I want this to be called each time the user logs in, using group policy, but so far I've had no luck.

The script is as follows:

Set oShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject( "Scripting.FileSystemObject" )

strUserName = oShell.ExpandEnvironmentStrings("%USERNAME%")
strTargetPath = oShell.ExpandEnvironmentStrings("%APPDATA%")

myURL = "http://example.com/tools/signature/build.php?user=" & strUserName
myPath = strTargetPath & "\Microsoft\Signatures\Default.htm"

Dim i, objFile, objFSO, objHTTP, strFile, strMsg
Const ForReading = 1, ForWriting = 2, ForAppending = 8

If objFSO.FolderExists( myPath ) Then
    strFile = objFSO.BuildPath( myPath, Mid( myURL, InStrRev( myURL, "/" ) + 1 ) )
ElseIf objFSO.FolderExists( Left( myPath, InStrRev( myPath, "\" ) - 1 ) ) Then
    strFile = myPath
Else

End If
Set objFile = objFSO.OpenTextFile( strFile, ForWriting, True )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )

objHTTP.Open "GET", myURL, False
objHTTP.Send
For i = 1 To LenB( objHTTP.ResponseBody )
    objFile.Write Chr( AscB( MidB( objHTTP.ResponseBody, i, 1 ) ) )
Next
objFile.Close( )

The Group Policy was setup against the 'User Configuration' in

Policies -> Windows Settings -> Scripts -> Logon

And this points to the script on the server.

When I run the script locally, it works without any visible errors and the signature is created correctly.

Can anyone see why this wouldn't run correctly, and where (if any) logs or errors would be written to on the server?

share|improve this question
    
You MsgBox statements to prove to yourself it is even being called in the first place. Have you checked the event log for errors? Have you checked with RSOP the user is getting the correct policy to run the script? Is there an error in your script so it fails, i.e. at the time its called by GroupPolicy have those ENV variables been set yet? –  jwbensley Feb 26 '13 at 10:41
    
I tried the MsgBox but didn't get any message when I logged out and back in again. There is nothing in the event viewer, and I also added WScript.Quit between Else / End If to prevent any errors if the path was invalid. I don't know how to use RSOP –  Alex Holsgrove Feb 26 '13 at 11:22
    
Pretty simply, log in and in the run box enter "rsop.msc", that should fire up Resultant Set of Policies, which you can use to check which Group Policy objects are being applied to you, to ensure you are being assigned the log on script! Search the Internet for more into on RSOP, there is loads. Also look at settings like "Always wait for the network at computer startup and logon to the computer" and similar, at the moment of Logon, you have to ensure the machine can see the network share on which the logon script resides. –  jwbensley Feb 26 '13 at 11:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.