StMaSi Posted February 15, 2017 Posted February 15, 2017 I'm trying to create a file on a network share, from a Windows 10 computer, but for whatever reason, I'm unable to do so. The file just isn't created. In addition, if I manually create the file myself and simply try to append data to it, that doesn't work either. The network share in question is completely unrestricted and all domain users have full control. Whether I use this to attempt to create a file... _FileCreate('"' & @ScriptDir & '\filename.txt' & '"') Or this to attempt to append to an existing file... FileWriteLine('"' & @ScriptDir & '\filename.txt' & '"', "This is a test." & @CRLF) Neither work. Can anyone assist with this? Thanks in advance.
Subz Posted February 15, 2017 Posted February 15, 2017 (edited) Use FileOpen function first with the flag set to 1 first for example: $hFileOpen = FileOpen(@ScriptDir & '\Filename.txt', 9) FileWrite($hFileOpen, 'This is a test') Edited February 15, 2017 by Subz Changed flag
StMaSi Posted February 15, 2017 Author Posted February 15, 2017 Yup, did that, but still no-go. Using FileOpen and FileClose before and after. Thanks.
spudw2k Posted February 15, 2017 Posted February 15, 2017 You are calling out @ScriptDir...so the script is executing from said network share, yes? Just double-checking. Reveal hidden contents Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
StMaSi Posted February 15, 2017 Author Posted February 15, 2017 Here's exactly what's happening... $mdate = StringReplace(_NowCalcDate(), "/", "") $mtime = StringReplace(_NowTime(5), ":", "") $mfile = @ComputerName & "." & $mdate & "." & $mtime & ".txt" $file = FileOpen('"' & @ScriptDir & '\' & $mfile & '"', 9) FileWrite($file, "This is a test.") FileClose($file) However, no file creation and no errors encountered. Thanks again.
Subz Posted February 15, 2017 Posted February 15, 2017 (edited) You should run this code within Scite and you'll notice that you have errors in the naming. Brain fade, should go to bed, this works for me on UNC using Windows 10 x64 #include <Date.au3> $mdate = StringReplace(_NowCalcDate(), "/", "") $mtime = StringReplace(_NowTime(5), ":", "") $mfile = @ComputerName & "." & $mdate & "." & $mtime & ".txt" ConsoleWrite($mfile & @CRLF) $file = FileOpen(@ScriptDir & '\' & $mfile, 9) FileWrite($file, "This is a test.") FileClose($file) Edited February 15, 2017 by Subz
spudw2k Posted February 15, 2017 Posted February 15, 2017 What is the path of the share? Is it a mapped drive or UNC path? If it's a mapped drive, are you elevating the script or using #RequireAdmin? You should also check $file to make sure it actually returned the handle, else FileWrite and Close will fail. Reveal hidden contents Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF
Subz Posted February 15, 2017 Posted February 15, 2017 Updated my post above, the issue was the quotes you have around the filename, it was attempting to create the file '"ComputerName.Date.Time.txt"'.
StMaSi Posted February 15, 2017 Author Posted February 15, 2017 On 2/15/2017 at 3:46 PM, Subz said: You should run this code within Scite and you'll notice that you have errors in the naming. Brain fade, should go to bed, this works for me on UNC using Windows 10 x64 #include <Date.au3> $mdate = StringReplace(_NowCalcDate(), "/", "") $mtime = StringReplace(_NowTime(5), ":", "") $mfile = @ComputerName & "." & $mdate & "." & $mtime & ".txt" ConsoleWrite($mfile & @CRLF) $file = FileOpen(@ScriptDir & '\' & $mfile, 9) FileWrite($file, "This is a test.") FileClose($file) Expand This worked! Thank you very much!!!
Subz Posted February 15, 2017 Posted February 15, 2017 Before I go just wanted to point out you could use $mfile = @ComputerName & '.' & @Year & @Mon & @MDay & '.' & @Hour & @Min & @Sec & '.txt'
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now