Sign in to follow this  
Followers 0
Fredr1k

Reg reading / RunAsSet

16 posts in this topic

Hi!

Im in the process of learning Autoit I have a specific mission to accomplish.

Heres what I need to do.

The script will start from a user login script.

The script will read the registry, if a specific dword exists and he value is 123456 the script will just exit.

The script should run as a specific domain user account (with administrative permissions on the PC.

The script will then run an external program \\server\share\mycoolapp.exe and wait for it to close.

The script will read the registry, if a specific dword exists and he value is 123456 the script will say upgrade is done, plz restart you computer, and write this to a \\server\share\success\computername.log file.

If the .exe application close but the dword value isnt 123456 it will say Upgrade fail and write this to a file \\server\share\fail\computername.log

Ok lets explain this :">

We have an application that needs to be updated, we cant upgrade the application but we need to. The application developer have provided us with a single .exe application that uninstalls/installs all this for us. When this is done successfully it writes the registry dword 123456. The application isnt aware if its already updated, if you run it its just doing all the things all over again, this is why we cant just run the .exe every time a user logon.

The users are just users on their PC and the local administrator account is disabled, this is why we need to run it as a domain specific user.

A few years ago I played around with Autoit and loved it, Ive been working with other systems for a long time now and feel like a beginner at this again.

So, can I do all I want with Autoit or do I need to write some other script to read the reg value thingies and then call the Autoit script?

Any info/example scripts are much appreciated for an old-new user :(

Regards,

Fredrik

Share this post


Link to post
Share on other sites



Okay there are several functions for you to look into.

Registry:

RegRead() <<Reads registry values.

Control Statements:

If...Then...ElseIf....EndIf <<Use in conjunction with RegRead to check your registry values.

Run Executables:

RunAsSet() <<Allows you to run as another user.

RunWait() <<Runs an external program and doesnt allow the script to continue until external is finished

Log File Creation/Writing:

FileOpen() <<Make sure you open it in append mode.

FileWriteLine() <<Writes a single line to a txt file.

If you havent already done so please install version 3. You will pick it all back up very quickly. Just check the helpfile for the above functions and I am pretty sure what you are wanting can be done.

JS


AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Share this post


Link to post
Share on other sites

Fredr1ck,

JS is right, it should be fairly simple to do. The one problem that you will need to watch out for, that is really no fault of AutoIt, is the timing during the actual logon process. Since you will be reading and writing to a remote sharepoint, as well as trying to authenticate a specific domain user account for the 'RunAs' function, I would suggest you make the Autoit routine one of the last entries in your logon script.

It seems like I have some code snippets around somewhere that do something similar to what your looking for, if I have a chance I will dig those up after work and see if they help you out.

ZK

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I'll start tapping away on it, when I'm done I'll post it for review.

ZenKensei, whatever you find I'll be happy to use :(

Thanks guys!

Edited by Fredr1k

Share this post


Link to post
Share on other sites

So, can I do all I want with Autoit or do I need to write some other script to read the reg value thingies and then call the Autoit script?

Any info/example scripts are much appreciated for an old-new user  :(

Fredrik,

yes you can do all this with AutoIT and without any external script. You would have to run the AutoIT script itsels with admin rights. The reason is, that RunAsSet only works with Run, but not with RegRead or other internal functions. See my suggestion on how to do it in the following thread. runasset Obviously, you will have to compile the script to at least obfuscate the admin password, in the script.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

To get the script to run after a user have logged on I'll use Sleep for 30 seconds, to prevent access problems described by ZenKensei.

Ok, so the script should be split up into three scripts?

Something like this:

Script 1

The script will start from a user login script.

The script will read the registry, if a specific dword exists and he value is 123456 the script will just exit.

If the script doesent find the regstring or value is something else than 123456 the script will start Script 2.

Script 2

The script should run as a specific domain user account (with administrative permissions on the PC.

The script will then run an external program \\server\share\mycoolapp.exe and wait for it to close.

When this is done it resets to users permissions and the starts Script 3.

Script 3

The script will read the registry, if a specific dword exists and he value is 123456 the script will say upgrade is done, plz restart you computer, and write this to a \\server\share\success\computername.log file.

If the dword value isnt 123456 it will say Upgrade fail and write this to a file \\server\share\fail\computername.log

Share this post


Link to post
Share on other sites

Ok, so the script should be split up into three scripts?

Why split the script? You can do it with one.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

This is confusing ?

If I use the script you posted and from the logonscript just specify \\server\share\thescript.exe it will switch to the account info added to the script?

And this is in you script is what makes it like this?

;******************************************************

;** If script was started without params restart it with

;** RUnAsSet

;******************************************************

RunAsSet( $username , $domainname, $password)

Run(@ScriptDir & "\" & @ScriptName & " /ra", @WorkingDir)

exit

endif

Ehum... so, if I copy you script, add my stuff below yours

(;- Your "privileged" Code HERE

)

My script will run all the way as admin?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

This is confusing ?

no, it's not :(

Ehum... so, if I copy you script, add my stuff below yours
(;- Your "privileged" Code HERE
)
My script will run all the way as admin?

correct. That's the purpose of my script. To have only one script, which is able

to restart itself with admin rights.

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Got it working, hade make it an .exe first, you thought I knew that one right :(

Share this post


Link to post
Share on other sites

Got it working, hade make it an .exe first, you thought I knew that one right :(

<{POST_SNAPBACK}>

Good. Regarding the EXE. I wrote that in my first post.

you will have to compile the script to at least obfuscate the admin password, in the script.

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

Kurt, thanks. I'm a bit "loopy" i guees.

Share this post


Link to post
Share on other sites

Kurt, thanks. I'm a bit "loopy" i guees.

<{POST_SNAPBACK}>

no problem...

Cheers

Kurt


__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Share this post


Link to post
Share on other sites

have run in to some problems

Ive got the script doing what I want, works fine with everything.

So I copied my stuff to the network and added it to the login script for testing and it dont work? So I started testing stuff, it just refuses? Then I copied it back to the local drive and again it runs fine. I need it to be running from where ever the user or script executes it, the reason is that we have a share that is replicated over some really slow WAN links at night, and the users execute the app from their local fileserver, in some cases the users dont have a local fileserver so they will get the app on CD and just run it from the local PC. So what I need to use is Run(@ScriptDir & "\" & "myapp.exe", @WorkingDir) so that I put my autoit compiled script and the program in the same folder

I get this error:

Line 0 (File i:\common\install\nameofscript.exe):

Run(@ScriptDir & "\" & @ScriptName & " /ra", @WorkingDir)

Error: Unable to execute the external program.

The system cannot find the path specified.

Ehh so ?

Share this post


Link to post
Share on other sites

have run in to some problems

Ive got the script doing what I want, works fine with everything.

So I copied my stuff to the network and added it to the login script for testing and it dont work? So I started testing stuff, it just refuses? Then I copied it back to the local drive and again it runs fine. I need it to be running from where ever the user or script executes it, the reason is that we have a share that is replicated over some really slow WAN links at night, and the users execute the app from their local fileserver, in some cases the users dont have a local fileserver so they will get the app on CD and just run it from the local PC. So what I need to use is Run(@ScriptDir & "\" & "myapp.exe", @WorkingDir) so that I put my autoit compiled script and the program in the same folder

I get this error:

Line 0 (File i:\common\install\nameofscript.exe):

Run(@ScriptDir & "\" & @ScriptName & " /ra", @WorkingDir)

Error: Unable to execute the external program.

The system cannot find the path specified.

Ehh so ?

<{POST_SNAPBACK}>

well, the runas-user has not maped the i drive, so use unc path (\\server\share\nameofscript.exe) or map the network drive before trying to start programms from the i drive

das beste Windows Support Forum: Windows 2000 Helpline und tschüss den WindowsfehlernProgrammieren: Autoit 3 - wer braucht noch VBS ?!Programmieren: Autoit 3 Forum?

Share this post


Link to post
Share on other sites

memnon, I thought it might be so... so let's see how to solve it.

I need to know from where the user executes the script, somehow "save" this info somewhere, and one of the first things I do is map this info in the script. Right?

So how do I do this :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0