从百度贴吧来到这里的新手
我想把AutoIT的代码转换成C++的,我是个C++菜鸟,这个我是当Demo用的,毕竟从HelloWorld开始不给力
代码在这里Func ActOffice14()
Local $file,$Osarh,$result,$i,$Flag=1
Select
Case @OSArch="X86"
$Osarh= RegRead ( "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" , "Path" )
If @error=1 Then
$Flag = 2
EndIf
Case @OSArch="X64"
$Osarh= RegRead ( "HKLM64\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" , "Path" )
If @error=1 Then
$Osarh= RegRead ( "HKLM64\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot" , "Path" )
If @error=1 Then
$Osarh= RegRead ( "HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot" , "Path" )
If @error=1 Then
$Osarh= RegRead ( "HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot" , "Path" )
If @error=1 Then
$Flag = 2
EndIf
EndIF
EndIf
EndIf
EndSelect
;执行激活命令
If $Flag <> 2 Then
RunWait(@ComSpec & ' /c net start osppsvc',"", @SW_HIDE)
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /remhst >> %windir%\actlog.log',"", @SW_HIDE)
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /sethst:127.0.0.2 >> %windir%\actlog.log',"", @SW_HIDE)
Sleep(4000)
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /act >> %windir%\actlog.log',"", @SW_HIDE)
;如果第一次失败则再尝试激活20次
For $i=1 To 20 Step 1
$file=FileOpen(@WindowsDir & "\actlog.log", 0)
While 1
Local $line =FileReadLine($file)
If @error = -1 Then ExitLoop
$result = StringInStr($line, "<Product activation successful>")
If $result <> 0 Then
$Flag=0
ExitLoop
Else
$Flag=1
EndIF
WEnd
If $Flag=1 Then
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /remhst >> %windir%\actlog.log',"", @SW_HIDE)
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /sethst:127.0.0.2 >> %windir%\actlog.log',"", @SW_HIDE)
Sleep(4000)
RunWait(@ComSpec & ' /c cscript "'&$Osarh&'"\ospp.vbs /act >> %windir%\actlog.log',"", @SW_HIDE)
Else
$i=20
EndIf
FileClose($file)
Next
RunWait(@ComSpec & ' /c echo [%time%] >> %windir%\actlog.log',"", @SW_HIDE)
EndIf
EndFunc
顺便提供一下命令行参数,把自身程序中RES文件提取到%Temp%并运行怎么实现
别忘了告诉TheSnow,我觉得AutoIT的中文汉化版的最新SVN,编译au3失败率较高,经常打开后显示没有脚本文件;还有编译出来的文件比官方版本大70-160KB(叫LZ我情何以堪);建议TheSnow提供单独编译器版,我爱用Notepad++ |