llewxam Posted May 20, 2009 Share Posted May 20, 2009 Hi folks. What I'm trying to do it script "takeown.exe" for use in a data backup app I am throwing together for work. Takeown /r should work recursively but for some reason won't, but when I run it (manually from a DOS box) without the /r it works fine. So I got ahold of a script to do the file/folder recursion for me, but now I can't get takeown to execute properly. I have tried runwait, shellexecutewait, and _rundos (and included #include process.au3 for the _rundos), and have tried including quotes in all the ways I know how to ensure that I wasn't having a path error. Here is a snippet of what I have currently, which looks like it should work, though it is incomplete in a few ways, still the takeown part looks good.expandcollapse popup$thisclean=0 if FileExists($sourcedrive&"documents and settings\"&$user&"\my documents")=0 then $thisclean=1 if $thisclean=0 then GUICtrlSetData($foundinfo, "The "&$user&" account is ready") if $thisclean=1 then $clean=1 if $clean=1 then $yesorno=msgBox(4,"Private folders found","The "&$user&" account was found to have private folders, would you like to take ownership of the profile?") if $yesorno=6 then $fa_dir=$sourcedrive&"documents and settings\"&$user shellexecuteWait(""""&@tempdir&"\takeown.exe""",$fa_dir) ;$thecommand=@tempdir&"\takeown.exe "&""""&$fa_dir&"""" (previous idea) call ("findall", $fa_dir) func findall($fa_dir) $f_search = fileFindFirstFile($fa_dir & "\*.*") if $f_search==-1 then return 0; specified folder is empty! while @error<>1 $f_file = fileFindNextFile($f_search) ; skip these if $f_file=="." or $f_file==".." or $f_file=="" then continueLoop endIf ; if it's a dir then call this function again (nesting the function is clever;) if stringInStr(fileGetAttrib($fa_dir & "\" & $f_file), "D") > 0 then shellexecuteWait(""""&@tempdir&"\takeown.exe""",$fa_dir) findall($fa_dir & "\" & $f_file) else ; File we need to dealwith shellexecutewait(@tempdir&"\takeown.exe "&""""&$fa_dir&"\"&$f_file&"""") endIf wEnd fileClose($f_search) return 1 endFuncAny help would be much appreciated. This is being run on XP using the takeown.exe available as part of the Win2k Resource Kit, if you need it for testing it can be downloaded hereIan My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
Authenticity Posted May 20, 2009 Share Posted May 20, 2009 You can add a few ConsoleWrite or MsgBox calls in the code to see how the path looks like. Maybe it's something like C:Document and Settings\blah... Link to comment Share on other sites More sharing options...
llewxam Posted May 20, 2009 Author Share Posted May 20, 2009 You can add a few ConsoleWrite or MsgBox calls in the code to see how the path looks like. Maybe it's something like C:Document and Settings\blah... hehe, already did with msgbox, all looked fine. For what it's worth, I forgot to mention that I use FileInstall("takeown.exe",@TempDir&"\takeown.exe",1) but have run items from @tempdir before with no problems...... Thanks Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
Authenticity Posted May 20, 2009 Share Posted May 20, 2009 What about: Run(@tempdir & '\takeown.exe "' & $fa_dir & '"') Link to comment Share on other sites More sharing options...
TurionAltec Posted May 20, 2009 Share Posted May 20, 2009 (edited) This: call ("findall", $fa_dir) can just be: findall($fa_dir) to more easily escape double quotes(") you can surround them with single quotes. Also it looks like you're trying to format your commands differently for each instances of takeown. We should see if we can get one working, and then move on. With Shellexecute the first parameter is the file name, and program parameters are supposed to be in the second parameter, so: shellexecutewait(@tempdir&"\takeown.exe "&""""&$fa_dir&"\"&$f_file&"""") becomes shellexecutewait(@tempdir&"\takeown.exe", '"'&$fa_dir&"\"&$f_file&'"') Edited May 20, 2009 by TurionAltec Link to comment Share on other sites More sharing options...
llewxam Posted May 20, 2009 Author Share Posted May 20, 2009 This: call ("findall", $fa_dir) can just be: findall($fa_dir) to more easily escape double quotes(") you can surround them with single quotes. Also it looks like you're trying to format your commands differently for each instances of takeown. We should see if we can get one working, and then move on. With Shellexecute the first parameter is the file name, and program parameters are supposed to be in the second parameter, so: shellexecutewait(@tempdir&"\takeown.exe "&""""&$fa_dir&"\"&$f_file&"""") becomes shellexecutewait(@tempdir&"\takeown.exe", '"'&$fa_dir&"\"&$f_file&'"') Thanks so much everyone for the help, especially the bit about single quotes surrounding double quotes, I've been curious about single quotes but haven't bothered looking for info on them. But, I did find a fix, what I have now (working) for the function is: func findall($fa_dir) $formattedfadir=""""&$fa_dir&"""" RunWait(@tempdir&"\takeown.exe "&$formattedfadir) $f_search = fileFindFirstFile($fa_dir & "\*.*") if $f_search==-1 then return 0; specified folder is empty! while @error<>1 $f_file = fileFindNextFile($f_search) ; skip these if $f_file=="." or $f_file==".." or $f_file=="" then continueLoop endIf ; if it's a dir then call this function again (nesting the function is clever;) if stringInStr(fileGetAttrib($fa_dir & "\" & $f_file), "D") > 0 then RunWait(@tempdir&"\takeown.exe "&$formattedfadir) findall($fa_dir & "\" & $f_file) else ; File we need to dealwith $formattedffile=""""&$fa_dir&"\"&$f_file&"""" runwait(@tempdir&"\takeown.exe "&$formattedffile) endIf wEnd fileClose($f_search) return 1 endFunc I may look in to the other options suggested here for experimentation's sake, but for now I'm gonna call it a win and move on When the project is completed, maybe I'll post it here for general suggestions/improvements/giggles at my noobishness Thanks again! Ian My projects: IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged. INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them. PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses. Sync Tool - Folder sync tool with lots of real time information and several checking methods. USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions. Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent. CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction. MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app. 2048 Game - My version of 2048, fun tile game. Juice Lab - Ecigarette liquid making calculator. Data Protector - Secure notes to save sensitive information. VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive. Find in File - Searches files containing a specified phrase. Link to comment Share on other sites More sharing options...
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