AutoIt DLL调用

时间:2011-02-28 18:37:16

标签: windows-7 autoit

我最近问了一个关于如何通过脚本设置Windows 7用户切片的问题。我在这里的博文中找到了答案:http://joco.name/2010/12/06/i-discovered-the-new-windows-user-tile-api/

我的问题是我不希望这个程序需要依赖.NET框架,所以我希望通过AutoIt3的DllCall()函数直接调用它。然而,无论我做什么,我都无法让它发挥作用:

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

我从-2147024894的调用中获得了返回值,一些谷歌搜索建议shell32.dll没有找到user_tile.jpg文件。更改为wstr后,此错误已消失,并已返回-2147221008。现在我卡住了,无法弄清楚我做错了什么,当我运行代码时没有任何反应(用户磁贴没有改变)。

有没有人有任何想法我做错了什么?

3 个答案:

答案 0 :(得分:3)

谢谢fejesjoco, 我也希望将示例代码从您的博客转换为AutoIt和 无法让它发挥作用。 CoInitialize建议做到了,您可以在this thread中找到AutoIt代码 在AutoIt论坛。

$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])

答案 1 :(得分:2)

你也可以问过那个博客的作者,他是一个乐于助人的人,我知道,因为这是我:)你应该检查你的线程是否在STA公寓。此外,您可能需要自己调用CoInitialize,在.NET中,框架会为您完成,但这是先决条件。

答案 2 :(得分:1)

博客提到您需要以MACHINE \ user或DOMAIN \ user格式指定用户名。除此之外,我认为你可以使用相对的图片路径,你不需要在shell32中安装它(然后你可能也不需要管理员权限),但是一旦你让它工作就试试。