Passing parameters from Group Policy to VBScript

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 05:09:58

问题


So i need to push a batch script out as a login script through Group Policy

Batch Script Example:

@echo off
Set USPS=%1 %2
Command %USPS%

I'm using a VB Script to call the .bat file

VB Script

Dim var1, var2
Set objShell = WScript.CreateObject("WScript.Shell")

'Parameter1, begin with index0
var1 = WScript.Arguments(0)

'Parameter2
var2 = WScript.Arguments(1)

objShell.Run "Script.bat" var1 & var2, 0, True

I'm placing parameters in the script parameters text box in group policy

So what im trying to do is pass the two parameters (Username and Password)to the VB Script then have the VB Script pass them to the batch file but it isn't passing them any like to point out where im messing up?

I'm doing it this way because i need to hide the username and password so i cant put them inside the scripts.

Thanks


回答1:


Here's how you can grab the args to your script and pass them along:

If WScript.Arguments.Count <> 2 Then
    WScript.Echo "This script needs two args."
    WScript.Quit -1
End If

Dim var1, var2
var1 = WScript.Arguments(0)
var2 = WScript.Arguments(1)

With CreateObject("WScript.Shell")
    .Run "Script.bat " & var1 & " " & var2, 0, True

   ' Or, if you want to leave the batch file out of this...
    .Run Chr(34) & "\\server\Folder\program.exe" & Chr(34) & " /remoteauth " & var1 & " " & var2
End With


来源:https://stackoverflow.com/questions/31006179/passing-parameters-from-group-policy-to-vbscript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!