Jump to content

Fun with batch files


Recommended Posts

Hi guys,

I'm very new to AutoIt, so new that this will be my 1st attempt at scripting using it. I need to install a new app on a whole bunch of pc's and most user don't have admin rights. I wrote a batch file that will map a drive and install the app and then disconnect the drive and I've been trying to get it to run under my admin account without any luck.

please have a look at what I have so far and make some suggestions

Runas ( "username", "domain", "password", "batfile.bat" [, "c:\" ] )

regards

Me

Link to comment
Share on other sites

The items with the brackets around them in the command lines are shown that way to indicate that they are optional, you shouldn't use the brackets in the actual commands when using them. Just write that line as : Runas ( "username", "domain", "password", "batfile.bat", "c:\" ) instead.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

ok, so I've decided to try this a bit differently

DriveMapAdd("W:", "\\servername\share", 0, "domain\username", "password")

Runas( "username","domain","pass","batfile.bat","W:" )

It maps the drive but the batch file never tries to run after that, any ideas?

all the batfile does is this

msiexec.exe /i w:\eavbe_nt32_enu.msi /qb! REBOOT="ReallySuppress" ADMINCFG=w:\cfg.xml

Edited by Knoffelstokkie
Link to comment
Share on other sites

all the batfile does is this

msiexec.exe /i w:\eavbe_nt32_enu.msi /qb! REBOOT="ReallySuppress" ADMINCFG=w:\cfg.xml

would it be useful to forget the batch file altogether?

_runDOS could issue the command much the same as the .bat would do. then we can rule out the bat file [which im thinking is the main problem here]

http://twentylinesofcode.blogspot.comLittle apps n crap. can be fun
Link to comment
Share on other sites

You have passed the 4th parameter (logon_flag) to the function as a string, when it should be a number. Try removing the double quotes as shown.

Runas( "username","domain","pass",2,"nod32.bat","W:" )

yeah, I changed it but I still get no result, is there any other way you guys can think of doing this?

I now have this

DriveMapAdd("W:", "\\servername\share", 2, "domain\username", "pass")

Runas("username","domain","pass", 4,"nod32.bat","W:")

and the batch file contains this

msiexec.exe /i w:\eavbe_nt32_enu.msi /qb! REBOOT="ReallySuppress" ADMINCFG=w:\cfg.xml

Link to comment
Share on other sites

would it be useful to forget the batch file altogether?

_runDOS could issue the command much the same as the .bat would do. then we can rule out the bat file [which im thinking is the main problem here]

Ok, _RunDOS confuses me completely, would you mind giving me some help in letting me do what I want done?

Link to comment
Share on other sites

Ok, _RunDOS confuses me completely, would you mind giving me some help in letting me do what I want done?

I think the "" in msiexec.exe /i w:\eavbe_nt32_enu.msi /qb! REBOOT="ReallySuppress" ADMINCFG=w:\cfg.xml

might cause some issues int the _RunDOS command.

also I was using runas so I can use my admin username and password on users pc's that don't have any install rights ;)

Edited by Knoffelstokkie
Link to comment
Share on other sites

yeah, I changed it but I still get no result, is there any other way you guys can think of doing this?

in view of:

program: The full path of the program (EXE, BAT, COM, or PIF) to run (see remarks)

i would suggest

Runas( "username","domain","pass",2,"W:\nod32.bat","W:" )

or whatever your full path is

HTH,

whim

Link to comment
Share on other sites

No idea (never used RunAS) but here's some thoughts

1) RunAs returns 0 on failure, so if that's the case, try other options ( maybe 0, interactive sounds like it might give you info ?)

2) If RunAs returns a valid PID your batch is at fault

whim

Link to comment
Share on other sites

No idea (never used RunAS) but here's some thoughts

1) RunAs returns 0 on failure, so if that's the case, try other options ( maybe 0, interactive sounds like it might give you info ?)

2) If RunAs returns a valid PID your batch is at fault

whim

nope not getting any response from the program ;)

Link to comment
Share on other sites

Have you tried running the batch file just by itself on a computer while logged in with the required credentials? In other words, does the batch file actually work without trying to run it from AutoIt? Have you tried it using the APPDIR= command line switch?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

You're not being very clear, but assuming that ...

nope not getting any response from the program

... means that RunAs returns 0, have you seen this (again, in the helpfile)

When running as an administrator, the Secondary Logon (RunAs) service must be enabled or this function will fail. This does not apply when running as the SYSTEM account

whim

Link to comment
Share on other sites

Have you tried running the batch file just by itself on a computer while logged in with the required credentials? In other words, does the batch file actually work without trying to run it from AutoIt? Have you tried it using the APPDIR= command line switch?

Yeah, batch file work perfectly on it's own and I can't find appdir in the helpfile

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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