Avatar of Snowy Canada
Snowy CanadaFlag for Canada

asked on 

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.
Windows OSWindows Server 2008Windows 7

Avatar of undefined
Last Comment
arnold
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of arnold
arnold
Flag of United States of America image

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.
Avatar of Snowy Canada
Snowy Canada
Flag of Canada image

ASKER

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.
Avatar of Snowy Canada
Snowy Canada
Flag of Canada image

ASKER

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?
Avatar of Snowy Canada
Snowy Canada
Flag of Canada image

ASKER

The GPO applied, I didn't run as administrator, but the route still not be added. thanks for any advice.
Avatar of arnold
arnold
Flag of United States of America image

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
SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Snowy Canada
Snowy Canada
Flag of Canada image

ASKER

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.
User generated image
SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Snowy Canada
Snowy Canada
Flag of Canada image

ASKER

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.
Avatar of NVIT
NVIT
Flag of United States of America image

Snowy,

In your test.vbs pic, pick Edit. Then enter according to my prior post.
Avatar of arnold
arnold
Flag of United States of America image

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.
Windows OS
Windows OS

This topic area includes legacy versions of Windows prior to Windows 2000: Windows 3/3.1, Windows 95 and Windows 98, plus any other Windows-related versions including Windows Mobile.

129K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo