how to run add logon VBS script as administrator

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.
Snowy CanadaNetwork AdministratorAsked:
Who is Participating?
 
NVITCommented:
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
1
 
arnoldCommented:
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.
0
 
Snowy CanadaNetwork AdministratorAuthor 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.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
Snowy CanadaNetwork AdministratorAuthor 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?
0
 
Snowy CanadaNetwork AdministratorAuthor Commented:
The GPO applied, I didn't run as administrator, but the route still not be added. thanks for any advice.
0
 
arnoldCommented:
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
0
 
NVITCommented:
In the Startup Properties, enter following:
Script name: cscript.exe
Script parameters: yourfilename.vbs
0
 
Snowy CanadaNetwork AdministratorAuthor 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
0
 
arnoldCommented:
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
0
 
Snowy CanadaNetwork AdministratorAuthor 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.
0
 
NVITCommented:
Snowy,

In your test.vbs pic, pick Edit. Then enter according to my prior post.
0
 
arnoldCommented:
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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.