简体   繁体   中英

Running batch from login script not working

I am hoping for assistance with a problem I have running a batch file called from a vbs login script. I do not do this often.

The Scenario: copy a small config file, for users who belong in a certain AD group to their local machine, to their program files (x86) folder, from directory %logonserver%\\sysvol\\ad.company.org\\scripts\\companyname\\country\\site ; also this where the VBS login script resides (actually, it's part of the login script but site specific and handles drive mappings) as well as the ASCII config file. Very simple.

Testing for the AD group is not a problem. The issue is I have a condition in the VBS script that tests for group membership, and if true I'm using Wscript.shell to run my batch, which is nothing more than setting robocopy to copy the config file to the user's local PC, but it doesn't run. I can manually run the batch from a test users's pc, no problem.

My VBScript looks like this (note that ADHelper is an object used from the main login script and I know it works):

Call updatePTP

    Sub updatePTP

    dim objShell
    set objShell = CreateObject("WScript.Shell")

    If ADHelper.IsCurrentUserMember("AD_Group-Name") Then
     objShell.Run("%logonserver%\sysvol\ad.company.org\scripts\companyname\country\site\test.cmd")
    End If

    Set objShell = Nothing

End Sub

I've also tried referencing from netlogon instead of sysvol


My Batch looks like this:

robocopy %source% %destination% %filename%

I'm thinking this probably has to do with something I don't quite understand about running a batch or program from the logon server on a user's PC, but I've taken a look at some of the older scripts that are no longer in use (but keep, anyway) and I'm essentially emulating what I've found in there... the script and batch themselves are easy enough to understand.

Thanks for any insight.

try this

Strlogonserver= CreateObject("WScript.Shell").ExpandEnvironmentStrings("%logonserver%")
If ADHelper.IsCurrentUserMember("AD_Group-Name") Then
     objShell.Run(Strlogonserver & "\sysvol\ad.company.org\scripts\companyname\country\site\test.cmd")
    End If

you cannot use system environment variables within the VB Strings. expand them beforehand

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM