Jump to content

Runasset Issues


Recommended Posts

Ok this is going to be querky, cuz as you all may know, i do things in a querky manner (so expect a querky script).

The basic idea of the following script is to catalog check the user's PC for the version of Serena Version Manager and output some info about it to a network share.

I am pushing this script out by way of GPO logon script.

but currently I am testing it locally on my PC.

The problem I am encountering is permissions related. Once It (the script) gets the information about the software application, it tries to write to a network log folder.

Ok Here's the querkiness.

It turns out that the log folder had RX permissions for regular users but RWX for Admins. I tried adding a func that had a RUNASSET line that would be called to write to the log file by way of FILEWRITELINE.

The problem is that it doesnt actually load the admin credentials to write to the log file.

I was doubting my Function skills so I commented out the function and opted out to insert the line of code inside every if statement (starting with the first one).

This is not the first time I've encountered a problem trying to do an autoit function as an admin, lately i even had trouble copying a file but I digress.

Any options, leads, workarounds or even explanation would be appreciated by this noob monkey.

#include<file.au3>

opt("trayiconhide", 1)

; Script Start - Add your code below here

$VM_link_file = "Merant Version Manager.lnk"

$VM_Path1 = "C:\WINNT\Profiles\All Users\Start Menu\Programs\Merant Version Manager Workstation\"

$VM_Path2 = "C:\WINNT\Profiles\All Users\Start Menu\Programs\"

$log_path = "\\servername\sharename\"

$log_file = "VM_Log.csv"

$user = @UserName

$password = "******"

;~ msgbox(0,"","Key Name " & " " &$Reg_Key &@lf & "Error: " & $reg_Query_Error)

if FileExists("c:\ntmarker\vmlog_pass.txt") then

FileDelete("c:\ntmarker\vmlog_pass.txt")

EndIf

if FileExists("c:\ntmarker\vmlog.txt") Then

;~ MsgBox(0,"file exists", "this has already been run")

Exit

elseif not FileExists("c:\ntmarker\vmlog.txt") Then

;~ MsgBox(0,"file exists", "this has not yet been run")

_FileCreate("c:\ntmarker\vmlog.txt")

FileOpen("c:\ntmarker\vmlog.txt",1)

FileWrite("c:\ntmarker\vmlog.txt","VMLOG script " & @MON& @MDAY & @YEAR & " " & @HOUR &":" & @MIN &@CRLF)

FileClose(":\ntmarker\vmlog.txt")

$Reg_Key = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Merant\Merant Version Manager\8.0.2.0", "InstallDir")

$reg_Query_Error = @error

if $reg_Query_Error=0 Then

;~ runwait(@ComSpec & " /c " & "echo found VM installed")

if FileExists($VM_Path1 & $VM_link_file) Then

$shortcut_value = FileGetShortcut($VM_Path1 & $VM_link_file)

;~ filewriteline($log_path & $log_file,@HOUR &":" & @MIN & "," & @MON &"/" & @MDAY & "/" &@YEAR & "," & @computername & "," &@UserName & "," & $shortcut_value[0]& "," & $Reg_Key )

;~ _VMLOG()

;~ MsgBox(0,"exists","Version Manager Exists" & @lf & $shortcut_value[0])

RunAsSet("admin"CPI", $password,2)

$fileopen_err = FileOpen($log_path & $log_file,1)

$write_err = filewriteline($log_path & $log_file,@HOUR &":" & @MIN & "," & @MON &"/" & @MDAY & "/" &@YEAR & "," & @computername & "," &@UserName & "," & $shortcut_value[0] & "," & $Reg_Key )

if $fileopen_err <> -1 Then

FileClose($log_path & $log_file)

EndIf

MsgBox(0,"Err", "error code for opening file: " & $fileopen_err & @crlf & "Error code for writing file: " &$write_err&@CRLF &$log_path & $log_file)

EndIf

if FileExists($VM_Path2 & $VM_link_file) Then

$shortcut_value = FileGetShortcut($VM_Path2 & $VM_link_file)

;~ filewriteline($log_path & $log_file,@HOUR &":" & @MIN & "," & @MON &"/" & @MDAY & "/" &@YEAR & "," & @computername & "," &@UserName & "," & $shortcut_value[0] & "," & $Reg_Key )

;~ _VMLOG()

;~ MsgBox(0,"exists","Version Manager Exists" & @lf & $shortcut_value[0])

EndIf

elseif $reg_Query_Error=1 Then

;~ filewriteline($log_path & $log_file,@HOUR &":" & @MIN & "," & @MON &"/" & @MDAY & "/" &@YEAR & "," & @computername & "," &@UserName & "," & "No VM Installed" )

;~ _VMLOG()

EndIf

endif

;~ func _VMLOG ()

;~

;~ RunAsSet("admin", "CPI", $password,1)

;~ $fileopen_err = FileOpen($log_path & $log_file,1)

;~ $write_err = filewriteline($log_path & $log_file,@HOUR &":" & @MIN & "," & @MON &"/" & @MDAY & "/" &@YEAR & "," & @computername & "," &@UserName & "," & $shortcut_value[0] & "," & $Reg_Key )

;~ if $fileopen_err <> -1 Then

;~ FileClose($log_path & $log_file)

;~ EndIf

;~ MsgBox(0,"Err", "error code for opening file: " & $fileopen_err & @crlf & "Error code for writing file: " &$write_err&@CRLF &$log_path & $log_file )

;~

;~ runasset()

;~ EndFunc

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Ok this is going to be querky, cuz as you all may know, i do things in a querky manner (so expect a querky script).

The basic idea of the following script is to catalog check the user's PC for the version of Serena Version Manager and output some info about it to a network share.

I am pushing this script out by way of GPO logon script.

but currently I am testing it locally on my PC.

The problem I am encountering is permissions related. Once It (the script) gets the information about the software application, it tries to write to a network log folder.

Ok Here's the querkiness.

It turns out that the log folder had RX permissions for regular users but RWX for Admins. I tried adding a func that had a RUNASSET line that would be called to write to the log file by way of FILEWRITELINE.

The problem is that it doesnt actually load the admin credentials to write to the log file.

I was doubting my Function skills so I commented out the function and opted out to insert the line of code inside every if statement (starting with the first one).

This is not the first time I've encountered a problem trying to do an autoit function as an admin, lately i even had trouble copying a file but I digress.

Any options, leads, workarounds or even explanation would be appreciated by this noob monkey.

it looks like this would definitely cause some problems, you may want to rexamine this line:

RunAsSet("admin"CPI", $password,2)
Link to comment
Share on other sites

it looks like this would definitely cause some problems, you may want to rexamine this line:

RunAsSet("admin"CPI", $password,2)
Thanks but that's an obfuscation error. when I cut and pasted the code i was deleting the real values.

the actual RUNASSET is correct (or else I wouldnt even be able to compile). Good eye though.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

Thanks but that's an obfuscation error. when I cut and pasted the code i was deleting the real values.

the actual RUNASSET is correct (or else I wouldnt even be able to compile). Good eye though.

From help file:

RunAsSet

Initialise a set of user credentials to use during Run and RunWait operations. 2000/XP or later ONLY.

You can split your admin function into a separate script and use RunAsSet and RunWait to run this script. Alternatively, have a look at this snippet http://www.autoitscript.com/forum/index.ph...topic=14710&hl=

Edited by SumTingWong
Link to comment
Share on other sites

From help file:

You can split your admin function into a separate script and use RunAsSet and RunWait to run this script. Alternatively, have a look at this snippet http://www.autoitscript.com/forum/index.ph...topic=14710&hl=

Thanks!

I converted all my functions to call out an external script. works like a charm!

Thank you again.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

From help file:

You can split your admin function into a separate script and use RunAsSet and RunWait to run this script. Alternatively, have a look at this snippet http://www.autoitscript.com/forum/index.ph...topic=14710&hl=

I added that to my favorites, once you get it working it's pretty damn amazing. I think this should definitely be considered to be added as a UDF maybe something like _FuncAsSet().

awesome stuff.

I kinda wish these forums had a "accepted answer" kinda like expert exchange.

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

Link to comment
Share on other sites

I added that to my favorites, once you get it working it's pretty damn amazing. I think this should definitely be considered to be added as a UDF maybe something like _FuncAsSet().

awesome stuff.

I kinda wish these forums had a "accepted answer" kinda like expert exchange.

The way I cobbled it together, it's not really suitable as a UDF as you have to insert your own code into the middle. Feel free to come up of a better way of presenting the code.

Edited by SumTingWong
Link to comment
Share on other sites

The way I cobbled it together, it's not really suitable as a UDF as you have to insert your own code into the middle. Feel free to come up of a better way of presenting the code.

well it's been working for me. Are those constants necessary?

---"Educate the Mind, Make Savage the Body" -Mao Tse Tung

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