AutoHotkey Community

It is currently May 27th, 2012, 3:13 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: March 28th, 2010, 11:43 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
I try to copy the file: C:\Windows\System32\GroupPolicy\Machine\Registry.pol, but it only works if i copy it by hand in a command line window :(

Code:
Source := A_WinDir . "\System32\GroupPolicy\Machine\Registry.pol"
Dest := A_Desktop . "\Registry.pol"

Loop, %A_WinDir%\System32\GroupPolicy\Machine\*
   Files .= A_LoopFileFullPath . "|"

IfExist , %Source%
   Source_Exist := 1
Else
   Source_Exist := 0
   
IfExist , %Dest%
   Dest_Exist := 1
Else
   Dest_Exist := 0
   
FileCopy , %Source% , %Dest% , 1
CopyResult := ErrorLevel

IfExist , %Dest%
   Dest_Exist_After := 1
Else
   Dest_Exist_After := 0

FileCopy , %A_ScriptFullPath% , %A_Desktop%\%A_ScriptName%_copy.ahk , 1
CopyTest := ErrorLevel

s_cmd := "xcopy /H """ . Source . """ """ . Dest . """"
RunWait , %ComSpec% /k "%s_cmd%" , , UseErrorLevel
RunError := ErrorLevel

IfExist , %Dest%
   Dest_Exist_CMD := 1
Else
   Dest_Exist_CMD := 0

output := "Source:" . A_Tab . A_Tab . Source . "`n"
      . "Destination:" . A_Tab . Dest . "`n"
      . "Files:" . A_Tab . Files . "`n"
      . "User is admin:" . A_Tab . A_IsAdmin . "`n"
      . "Source exist:" . A_Tab . Source_Exist . "`n"
      . "Destination exist:" . A_Tab . Dest_Exist . "`n"
      . "Copy result:" . A_Tab . CopyResult . "`n"
      . "Exist after: " . A_Tab . Dest_Exist_After . "`n"
      . "Copy Test:" . A_Tab . CopyTest . "`n`n"
      . "Command:" . A_Tab . s_cmd . "`n"
      . "ErrorLevel:" . A_Tab . RunError . "`n"
      . "Dest exist CMD:" . A_Tab . Dest_Exist_CMD
      
MsgBox , %output%


Copying "by hand" in a command line window works: Image

Copying with ahk fails with FileCopy and also with RunWait cmd.exe /k xcopy ...
Image Image

The question in the first picture means: is the destination a file (Datei) or folder (Verzeichnis) and 1 file(s) copied. The other cmd picture shows 0 file(s) copied.

edit:
I think it matters: I use Windows 7 x64.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: March 29th, 2010, 12:23 am 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
ladiko wrote:
Code:
; ........
s_cmd := "xcopy /H """ . Source . """ """ . Dest . """"
RunWait , %ComSpec% /k "%s_cmd%" , , UseErrorLevel
; ........
Try this
Code:
s_cmd := `"""xcopy`"" " `"""/H`"" " `"""" Source `""" " `"""" Dest `""""
RunWait , %ComSpec% /k "%s_cmd%" , , UseErrorLevel
Let me know if this works.
ladiko wrote:
edit:
I think it matters: I use Windows 7 x64.
Agreed, you may have to give administrative permission.

hth

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2010, 2:38 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
Hello TLM :-)

In the third picture, you can see that I executed it with administrative rights. If i execute it normal A_IsAdmin is zero. Your advice results in "invalid number of parameters". I think it's not the syntax, but it seems to me like windows protects the files from access by programs!?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2010, 5:40 pm 
Offline

Joined: August 21st, 2006, 7:07 pm
Posts: 2925
Location: The Shell
ladiko wrote:
Your advice results in "invalid number of parameters". I think it's not the syntax, but it seems to me like windows protects the files from access by programs!?
Have you tried taking a step backward just to make sure everything works ok?

Just to debug the s_Cmd line, try entering the parameters directly in the commandline itself.
Code:
; ..............
RunWait , %ComSpec% /k ""xcopy" "/H" "%Source%" "%Dest%"",, UseErrorLevel


hth

_________________
Imageparadigm.shift:=(•_•)┌П┐RTFM||^.*∞


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 29th, 2010, 10:23 pm 
Offline

Joined: July 14th, 2006, 12:31 am
Posts: 290
Location: Berlin
the windows 7 taskmanager shows with which command and parameters a process was called. exactly this command works in a normal command line window. i really double checked it all, cause it's not logically. the following also works as restricted user without administrative rights in a manually started command line window:
Code:
cmd.exe /k xcopy /h C:\Windows\System32\GroupPolicy\MACHINE\Registry.pol D:\


Image Image

i did some more testing:

1.) start a cmd.exe by ahk, send the command to the window{enter} -> doesn't work
2.) start a cmd.exe by ahk, type the command manually, enter -> doesn't work
3.) start a cmd.exe manually, type the command manually, enter -> works
4.) start a cmd.exe manually, send the command by ahk{enter} -> works

so it seems like windows 7 doesn't allow AHK to access this file!?

this is the code for case 1:
Code:
Run , cmd.exe
the_command := "cmd.exe /k xcopy /h C:^!ßWindows^!ßSystem32^!ßGroupPolicy^!ßMACHINE^!ßRegistry.pol D:^!ß"
WinWait , C:\Windows\system32\cmd.exe
WinActivate , C:\Windows\system32\cmd.exe
Sleep , 500
Send , %the_command%{Enter}
^!ß is the german keystroke to get a backslash ( \ ).

Seems to be this:
Quote:
WRP also protects several critical folders. A folder containing only WRP-protected files may be locked so that only the Windows trusted installer SID is able to create files or subfolders in the folder. A folder may be partially locked to enable administrators to create files and subfolders in the folder.
Source: http://en.wikipedia.org/wiki/Windows_Re ... Protection


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], rbrtryn and 28 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group