how to run add logon VBS script as administrator

Snowy Canada
Snowy Canada used Ask the Experts™
on
Question: I need when domain users log on, VBS logon script will be run include this command: route add /p 201.2.3.4 mask 255.255.255.255 10.10.10.10. This command need administrator or elevated user mode.  How to do it from VBS script? Could you give me a sample?

Environment:
Server level Windows Server 2008 R2
Desktops: Windows 7

I know this question had been asked many many times, but my situation is a little bit special. I don't want users type in administrator account name and password. I don't want my administrator account name and password recorded in VBS script and be found by any personal who can access server and edit the VBS file.

Thank you.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
End-user support
Commented:
You could run it in a gpo when the system starts up as a Computer Startup Script. That way, you don't worry about the user's running it.
https://www.petri.com/run-startup-script-batch-file-with-administrative-privileges
Distinguished Expert 2017

Commented:
Why not configure this as a scope option on the DHCP server?
Add route directive .
The other option is to add the route of the upper router/firewall,.

Seems like this is a route through VIP that routes to the destination via a VPN.
Snowy CanadaNetwork Administrator

Author

Commented:
Thank you for your suggestions.

Sorry for did not reply or make the solution choice. These days I have been pushed to focus on other projects, didn't have time to try the options. I will go back to the line as soon as possible.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

Snowy CanadaNetwork Administrator

Author

Commented:
I  made a VBS file and added these commands

Set objShell = WScript.CreateObject("WScript.Shell")
wscript.sleep 100
Set objExecObject = objShell.Exec("%comspec% /c route add 123.123.0.0 mask 255.255.0.0 10.10.1.1 ")

Then add this VBS file into startup script folder.
Linked GPO to the OU in which the test computer locate and enforced.
After reboot test computer and login, I checked result via route print command. The route wasn't added.
Try GPResult /r, find the GPO didn't applied. Any advice to help me go through the trouble?
Snowy CanadaNetwork Administrator

Author

Commented:
The GPO applied, I didn't run as administrator, but the route still not be added. thanks for any advice.
Distinguished Expert 2017

Commented:
Set objShell = WScript.CreateObject("WScript.Shell")
wscript.sleep 100
Set objExecObject = objShell.Exec("%comspec% /c 'route add 123.123.0.0 mask 255.255.0.0 10.10.1.1' ")

Open in new window


run the vbscript first to make sure what happens.

note the 10.10.1.1 has to be on the system for it to add the route
NVITEnd-user support
Commented:
In the Startup Properties, enter following:
Script name: cscript.exe
Script parameters: yourfilename.vbs
Snowy CanadaNetwork Administrator

Author

Commented:
Hi Arnold,
I can't run the VBS because it need administrator permission, that's why I need to run Computer Configuration/startup script.
Hi NVIT,
The script file is added, just as the picture shows.
12345.JPG
Distinguished Expert 2017
Commented:
see nvits suggestion to include/cscript or use a batch script .bat
@echo  off
route.exe add 123.123.0.0 MASK 255.255.0.0 10.10.1.1
The issue as noted the gateway, 10.10.1.1 must be an IP on the system not a destination IP.

test the script to make sure it runs when elevated mode.
Computer configuration runts with system rights, and should set the parameters if correct.

or use the following powershell cmdlet:
https://technet.microsoft.com/en-us/library/hh826148(v=wps.630).aspx
Snowy CanadaNetwork Administrator

Author

Commented:
Yes, run the VBS under administrator privileges, the route added. I could turn around and try Powershell, but  still can't understand from computer startup script, why this VBS file doesn't work.
NVITEnd-user support

Commented:
Snowy,

In your test.vbs pic, pick Edit. Then enter according to my prior post.
Distinguished Expert 2017

Commented:
Have not tried, but NVIT's earlier point deals with whether running .vbs file would run,unless specified differently.
Looking in the event log on the test machine during bootup, to see what happened when the startup script ran.
Adding the -p option to make the route permanent.

Depending on the relationship of the gateway to the computer, a better approach would be to add this rule on the rputer where these workstations vonnection in the absence of pushing this route via DHCP server scope options route rule.

Another possible way is to run in a GPO with loopback processing, while the bat file route add or powershell cmdlet new-roure.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial