Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass credentials in script to access network resource. 1

Status
Not open for further replies.

theniteowl

Programmer
May 24, 2005
1,975
0
0
US
My apologies if this shows up twice but after hitting submit on the last one it never showed in the forum and I assume it was lost.

I have a VB Script application that monitors files on a network share. The server is logged into with a local account that does not have access to the share but this has not been a problem when using Stored Usernames and Passwords to setup the correct credentials for the shares.
A recent policy change locked us out of using the stored credentials so now when the app tries to access the network resource it fails because the only credentials it has to use are the current login.

Is there a way in VBS to establish a connection to the network share passing it the credentials you want to use?
Right now I have to manually attempt a connection to the share which after a long wait finally comes up with a logon screen where I can manually enter the info. Once done this will continue to work until the authentication expires or the server is rebooted, etc. This can result in the app losing connection at unforseen times and causing production problems.

Is it possible to connect to a UNC path and push the authentication credentials along with it rather than having to manually re-authenticate to every share on every server when they fail?

Thanks.


At my age I still learn something new every day, but I forget two others.
 
Mapped drives are not an option so I need to find a programmatic way to do it.

At my age I still learn something new every day, but I forget two others.
 
RunAs.exe. At a command prompt, type runas /? to see valkid options. Not sure if you can setup a scheduled task to do this or if you need a driver (parent) script. To launch another script using runas with objShell requires A LOT of quotes!It requires quotes.

About half-way down the following thread, I go into "detail" about using runas with objShell


-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
essentially, you driver program should look like

Code:
set objShell = CreateObject("WScript.Shell")

objShell.Run [blue]"RunAs /noprofile /user:domain\username [red]""cscript.exe [green]\""C:\Development\VBS\monitor.vbs\""[/green]""[/red]"[/blue]

this runs monitor.vbs (your presumed network files monitor) as domain\username thus "passing" credentials to the script.

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Thanks Geates, I will give it a try. Out in a training class all day today.

We are in the midst of an application upgrade and moving to new VMS servers at the same time. At that time we can switch to logging into the server with the domain account that has access to these shares so as long as the domain account has privledges to run the local vbs app it will not be a problem but then again, it might so this code could help me in both situations.
Someday I will convince them to buy me a compilable programming language where I will have more options but...


At my age I still learn something new every day, but I forget two others.
 
I forgot, it'll prompt for a password. I you haven't something to accommodate for this, do so by using objShell.sendkeys

Code:
set objShell = CreateObject("WScript.Shell")objShell.Run "RunAs /noprofile /user:domain\username ""cscript.exe \""C:\Development\VBS\monitor.vbs\"""""

wscript.sleep 1000 'milliseconds

strPassword = "something"
objShell.sendkeys strPassword
objShell.sendkeys "{enter}"

-Geates

"I hope I can chill and see the change - stop the bleed inside and feel again. Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top