Jump to content

Dir creation problem - (Moved)


Siva88
 Share

Recommended Posts

Hi, I need to create a folder under "C:\Program Files\Mozilla firefox". But the challenge is i'm running the script as non-elevated user and even i can mention the username and password of admin credentials. I need a script for creating a folder under that directory and need to paste one file from network.

Link to comment
Share on other sites

the folder "C:\Program Files" is protected by windows itself against write access without elevated rights ("Run as administrator", it's even not sufficent to be locally logged on as member of the local group "Administrators"!)

add the line ...

#RequireAdmin

... on top of your script, *IF* you really need to write to that folder.

 

Another option would be not to "pull" the file from the workstation, but to "push" it from the server side. Either by a Script, or using GPO.

 

CU, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

can you  please tell me why this script is not working..

#include <AutoItConstants.au3>
#include <StringConstants.au3>
#include <File.au3>
#include <array.au3>
$file = "C:\mscript\ips.txt"
FileOpen($file, 0)
$fileuser = "C:\mscript\username.txt"
FileOpen($fileuser, 0)
$uname = FileReadLine($fileuser, 1)
$passwd = FileReadLine($fileuser, 2)

For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)
Local $sOutput = ""
Local $sOutPath = "C:\mscript"
$sFileName = $sOutPath &"\browseroutput"
$hFilehandle = FileOpen($sFileName, $FO_APPEND)
Global $sData = FileRead("C:\mscript\browseroutput.txt")    ; Read the RSS File you will need to change the path to match the location on your PC
$sRemoteLocalPath = "c:\TNI\"
$LocalFile = "browser.bat"
Local $testing = Run('D:\Downloads\PSTools\PsExec.exe -nobanner \\' & $line & ' "' & $sRemoteLocalPath & $LocalFile & '"', '', @SW_SHOWDEFAULT)
ConsoleWrite("Browser :" & $testing)
Do
    Sleep(100)
Until @error ; error occurs when command has finished

$sOutput = StringStripWS($sOutput, $STR_STRIPALL) ; remove all @cr and spaces from output
FileWrite($hFilehandle, @CRLF & "Name="&$line& ' ' & $sOutput & @CRLF)
Next
FileClose($file)

Link to comment
Share on other sites

You're not using FileOpen properly. It returns a handle to the file that you write and read with.

Take a close look at the examples in the HelpFile...

https://www.autoitscript.com/autoit3/docs/functions/FileOpen.htm

 

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

33 minutes ago, ripdad said:

You're not using FileOpen properly. It returns a handle to the file that you write and read with.

Yes !

Note from The Help : "Do not mix filehandles and filenames, i.e., don't FileOpen() a file and then use a filename in this function. Use either filehandles or filenames in your routines, not both!"

A proper variable declaration could also not do any harm ;). Place the following statement at the beginning of the script :

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 6 -w 7

or at least use :

Opt("MustDeclareVars", 1)

Global and Local declarations within loops are not recommended.

Last but not least : Read Best_coding_practices

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

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