WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

64-bit

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

wntAccessAdd Redirection on WinXp x64

 Keywords: wntAccessAdd Redirection  WinXP Win XP x64 64-bit 64

Question:

Using the 32-bit version of WinBatch 2009C on Windows XP 64-bit. I am trying to create a subdirectory in the C:\Windows\System32 directory and give the Users group 'change' permissions using wntAccessAdd. I know the C:\Windows\System32 directory is a 64-bit, so I am disabling file redirection using IntControl 92. The redirection works fine when I create the directory using DirMake. However it fails to set access permissions using wntAccessAdd. I get the error: wntAccessAdd 547: Error accessing file/directory information when running on Windows Xp x64.
AddExtender("WWWNT34I.DLL")
sPath  = 'c:\Windows\System32\Test'

; Disable redirect
oldvalue = IntControl( 92, "disable", 0, 0, 0 )

;Delete and recreate directory
if DirExist(sPath) then DirRemove(sPath)
DirMake(sPath)

;Add permissions
wntAccessAdd("", sPath, "Users", 300, "Dir:Change") 
Pause(sPath,"Successfully applied permissions")

; Remove test directory
DirRemove(sPath)
Pause(sPath,"Successfully removed test directoy")

; Enable redirect
IntControl( 92, "revert", oldvalue, 0, 0 )

Answer:

wntAccessAdd and redirection seem to work fine on Win7 and Vista x64 so it's probably a bug in XP x64. The only thing against that, is the fact that we didn't find any bug reports regarding this.

Based on our testing it turns out that the file redirection issue is only on Windows XP x64. So you have a couple of options.

Option 1: Use CACLS
;cacls c:\windows\system32\test /t /e /g Users:c sCacls = "c:\windows\system32\cacls.exe"
sFolder  = "c:\Windows\System32\Test"
sParam = "/t /e /g Users:c" ;Users Change 

; Disable redirect
oldvalue = IntControl( 92, "disable", 0, 0, 0 )

;Delete and recreate directory
if DirExist(sFolder) then DirRemove(sFolder)
DirMake(sFolder)

;Add permissions
Pause(sFolder,"Before applying permissions") 
ShellExecute(sCacls, sFolder : " " : sParam, FilePath(sFolder), @NORMAL, "") 
Pause(sFolder,"Successfully applied permissions")


; Remove test directory
DirRemove(sFolder)
Pause(sFolder,"Successfully removed test directoy")

; Enable redirect
IntControl( 92, "revert", oldvalue, 0, 0 )


Option 2: Use Sysnative with a symbolic link ( junction )
As an alternative to using IntControl 92, you can generally use 'Sysnative' where you mean 'system32' in the file paths. Except on Windows Xp x64 and Window 2003 x64 you must install a hotfix for this to work. Or you can create a symbolic link to the real system32 folder using the linkd command before running the script.
linkd c:\windows\Sysnative c:\windows\system32
We have tested this and it does work. I don't think the linkd command comes with WinXP x64 but it can be download from MSFT. I think it is part of the Win2k3 resource kit. Or you can use the free Sysinternals download that makes symbolic links Junction v1.05

sPath = 'c:\Windows\Sysnative\Test'
Complete example:
AddExtender("WWWNT34I.DLL")
sPath  = 'c:\Windows\Sysnative\Test'

;Delete and recreate directory
if DirExist(sPath) then DirRemove(sPath)
DirMake(sPath)

;Add permissions
wntAccessAdd("", sPath, "Users", 300, "Dir:Change") 
Pause(sPath,"Successfully applied permissions")

; Remove test directory
DirRemove(sPath)
Pause(sPath,"Successfully removed test directoy")

Details: http://msdn.microsoft.com/en-us/library/aa384187(VS.85).aspx
32-bit applications can access the native system directory by substituting %windir%\Sysnative for %windir%\System32. WOW64 recognizes Sysnative as a special alias used to indicate that the file system should not redirect the access. This mechanism is flexible and easy to use, therefore, it is the recommended mechanism to bypass file system redirection. Note that 64-bit applications cannot use the Sysnative alias as it is a virtual directory not a real one.


Another option is to


Article ID:   W17651
Filename:   wntAccessAdd Redirection on WinXp x64.txt
File Created: 2009:10:07:08:48:08
Last Updated: 2009:10:07:08:48:08