Jump to content
Sign in to follow this  
Meldrath

elevating FileOpen() to allow for read/write at Admin level

Recommended Posts

Meldrath

I am trying to elevate my FileOpen() to read a file that is remote (no problem there), and unfornately needs to have elevated permissions to be read. Any help? Can not use any other 3rd party software to help with this other than this script.

Share this post


Link to post
Share on other sites
Meldrath

No this is being done on a remote computer that the users have no access to admin info. I know how to runas, but I can not properly either get the whole script elevated to admin level or an individual function or just the FileOpen() function.

Share this post


Link to post
Share on other sites
Vincor

Hmmm, I see.

Next questions would be:

- Are these computers (yours, remote?) in a domain?

- Are you admin in that domain?

- Are you running your script locally or at the remote computer?

Maybe you'd solve this with e.g. PSTools by SysInternals?

Share this post


Link to post
Share on other sites
Meldrath

They are my remote computers (work), I am an admin, and I'm running the script remotely.

Func ReadFile($ecmlocation)

$file = FileOpen($ecmlocation)
;Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf

;Read in lines of text until the EOF is reached
$eachline=1 ;line to be read
While $eachline <4 ;line by line until line 4
$line = FileReadLine($file)
$PosOfStore = StringInStr ($line,"glob_store_code=") ;it looks for the string "glob_store_code=", >0 means found something matching that!
if $PosOfStore >0 Then ;if does not find it will quit the loop
$store_id = stringmid($line, $PosOfStore + 20,4) ; if it finds something it will grab the store ID Ex: 003A
ExitLoop
Else
$store_id ="nothing" ; if does not find anything it will quit and return "nothing"
EndIf
Wend
FileClose($file)
Return $store_id
EndFunc

I am trying to get this to pull up from the 2nd terminal, information on the first terminal, but it requires elevation to open the file on that network as both computers there are users.

Edited by Meldrath

Share this post


Link to post
Share on other sites
Vincor

See this post:

Then add a -s to your psexec calls, when using your admin credentials. That will enable running as system. (http://ss64.com/nt/psexec.html)

Plus, your code needs some polishing. Your loop doesn't seem right. That $eachline is not going anywhere...

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  

×