开发者

AutoIt DllCall() shell32.dll

开发者 https://www.devze.com 2023-02-13 19:00 出处:网络
How to setup Windows 7 user tiles via a script I found explained in a blog post. But I do not want the .NET framework dependency this requires, so I try to call it directly via DllCall(). However I ca

How to setup Windows 7 user tiles via a script I found explained in a blog post. But I do not want the .NET framework dependency this requires, so I try to call it directly via DllCall(). However I cannot get this to work:

#RequireAdmin
FileCopy("user_tile.jpg", "C:\Windows\system32\user_tile.jpg")
$rtn = DllCall(@SystemDir & "\shell32.dll", "long", 开发者_Go百科262, "wstr", "ahiscox", "int", 0, "wstr", "C:\Windows\system32\user_tile.jpg")
MsgBox(16, "DLL Return", $rtn[0])

I got a return value of -2147024894 (seems shell32.dll wasn't finding user_tile.jpg). After changing to wstr this returns -2147221008. When I run the code nothing happens (the user tile is not changed).


Thanks fejesjoco, I too was looking to convert the sample code from your blog to AutoIt and couldn't get it to work. The CoInitialize suggestion did it, you can find the AutoIt code in this thread in the AutoIt forums.

$sUserName = "DOMAIN\rvdmast"
$sPicPath = "\\server\data\fotos\rvdmast.jpg"

; call CoInitialize
DLLCall("ole32.dll","int","CoInitialize","ptr",0)

$hPicPath = DLLStructCreate("wchar[128]")
DllStructSetData($hPicPath, 1, $sPicPath)

$hUserName = DLLStructCreate("wchar[128]")
DllStructSetData($hUserName, 1, $sUserName)

$aRet = DllCall(@SystemDir & "\shell32.dll", "long", 262, "ptr", DllStructGetPtr($hUserName), "int", 0, "ptr", DllStructGetPtr($hPicPath))

MsgBox(4096, "SetUserTile", $aRet[0])


You could also have asked the author of that blog, he's a helpful guy, I know it because it's me :) You should check if your thread is in an STA apartment. Also you might need to call CoInitialize yourself, in .NET the framework does it for you but it's a prerequisite.


The blog mentions that you need to specify the username in MACHINE\user or DOMAIN\user format. Other than that, I think you can use the relative picture path and you don't need to install it in shell32 (and then you probably won't need admin rights either), but try that once you get it working.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号