Jump to content

Map a drive in WINPE using a variable from the first line of a text file


Go to solution Solved by EndFunc,

Recommended Posts

Posted

I'm having some issues with an AUTOIT script and was wondering if someone could help me troubleshoot what I am doing wrong. I've looked through all the help files and can't seem to find out where I'm going wrong.

 

I have a script that maps the z drive successfully if I do not pull the variable from the text file. The following below works fine in the PE environment. Unfortunately I need to pull the variable from a text file on the machine that runs it because the server.domain.com will change depending upon machine.

Script 1 (works)

Global $server = 'server.domain.com'
MsgBox( 0, "variable value", $server)
DriveMapAdd("Z:", "\\" & $server & "\deployment", 0, "domain.com\useraccount", "(password)")

The script does not work:

Global $sFilePath = @ScriptDir & "\servervar.txt"


FileOpen($sFilePath, 0)


Global $server = FileReadLine( "servervar.txt" )


MsgBox(0, "variable value", $server)


DriveMapAdd("Z:", "\\" & $server & "\deployment", 0, "domain.com\useraccount", "(password)")
I added the Msgbox to confirm that the $server variable was indeed gathering the correct data, and it does have the correct data that i would expect.
 
Can anyone tell me why first script would work, but the 2nd will not? Like I said the 2nd script MsgBox is displaying the same data that i set manually with in the first script. I am new to autoit so if it's something really silly I apologize in advance.
 
Any help would be much appreciated!
Posted

"doesn't work"; doesn't help much ;)

What error does the DriveMapAdd exit with? Throw a MsgBox after it, looking for @error.

By "doesn't work" i meant it doesn't map the drive.

The @error that is displaying is 1.   

Posted

 

Make sure there are no spaces or new lines in the file. That might be causing some issues.

Maybe try

Global $server = StringStripWS(FileReadLine( "servervar.txt" ), 8)

You are awesome! This is exactly what solved my problem. It must have been grabbing to many characters instead of only the characters listed. Thanks so much for your help!

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...