2015-04-05 42 views
0

我想弄清楚如何編寫一個批處理文件,我可以在多臺計算機上使用來設置背景。我嘗試了一些我在其他搜索中看到的一些建議,但除此之外,我不確定如何執行此操作。任何人有任何建議?謝謝!在XP中設置壁紙的腳本?

+0

http://stackoverflow.com/questions/7779491/changing-wallpaper-with-a-batch-file-on-program-close-possible – user3719066 2015-04-05 21:52:59

+0

我看到了在我的搜索類似的問題,現在我有批處理文件說成功完成,但背景並沒有真正改變... – Raistlin 2015-04-05 22:11:21

回答

0

線使用的是:在關於該命令的信息的命令提示窗口reg add /?

@%SystemRoot%\System32\reg.exe add "HKCU\Control Panel\Desktop" /v Wallpaper /t REG_SZ /d "C:\Windows\winnt.bmp" /f 

運行。

我真的很驚訝,你自己找不到,因爲已經有Changing Wallpaper with a batch file, on program close. Possible?而在[batch-file] wallpaper上搜索堆棧溢出會返回41個結果。

+0

啊,我想我在開始時錯過了「@%SystemRoot%\ System32 \」 。現在彈出的窗口要求確認,並表示已成功完成;但是,它並沒有真正刷新壁紙。有什麼我需要得到它來更新? – Raistlin 2015-04-05 22:07:34

+0

'@'只是在執行時隱藏命令並且'%SystemRoot%\ System32'通常是不需要的,因爲這個目錄默認是在Windows XP環境變量'PATH'中的第一個目錄。更改Windows註冊表值當然不會導致Windows桌面的刷新。但是,這不應該打擾你,因爲用戶在下次Windows登錄後會自動顯示牆紙。由於壁紙是一種用戶設置,我不太喜歡你想要做的事情,因此不會進一步幫助。抱歉。 – Mofi 2015-04-05 22:22:05

+0

如果您想在vbscript中發佈代碼,並在Windows 7 32位上測試HTA(禁用UAC),請使用HTA。只是編輯你的文章,並添加這些標籤vbscript和HTA – Hackoo 2015-04-05 22:33:55

0

此HTA在下測試,Windows 7 32位,UAC禁用。只是嘗試一下你的XP,並告訴我它是否會起作用。 祝你好運!

ChangeWallpaper.hta

<html> 
<head> 
<title>Application pour changer le fond d'écran dans Windows 7 © Hackoo © 2013</title> 
<HTA:APPLICATION 
APPLICATIONNAME="Application pour changer le fond d'écran dans Windows 7" 
ID="Application pour changer le fond d'écran dans Windows 7" 
ICON="Explorer.exe" 
BORDER="dialog" 
INNERBORDER="no" 
MAXIMIZEBUTTON="No" 
SCROLL="no" 
VERSION="1.0"/> 
<style> 
Label 
{ 
color : #123456; 
font-family : "Courrier New"; 
} 
BODY {background-color:DarkOrange;} 
input.button { background-color : #EFEFEF; 
color : #000000; cursor:hand; 
font-size: 11px; font-family: Verdana, Arial, Helvetica, sans-serif; } 
} 
.alt2, .alt2Active 
{ 
background: #E1E4F2; 
color: #000000; 
}  
</style> 
</head> 
<META HTTP-EQUIV="MSThemeCompatible" CONTENT="YES"> 
<script language="VBScript"> 
Option Explicit 
Dim Titre,fso,MyFolder,TabFolder,DossierCourant,DossierCourantIMAGE 
Titre = "Application pour changer le fond d'écran dans Windows 7 © Hackoo © 2013" 
set fso = CreateObject("Scripting.FileSystemObject") 
MyFolder = fso.GetAbsolutePathName(".") 
TabFolder = Split(MyFolder,"\") 
DossierCourant = TabFolder(UBound(TabFolder)) 
DossierCourantIMAGE = DossierCourant&"_IMAGE_FOND" 
If Not fso.FolderExists(DossierCourantIMAGE) Then 
    CreateFolder(DossierCourantIMAGE) 
End if 
'***************************************************************** 
Sub Window_OnLoad 
    CenterWindow 640,200 
End Sub 
'***************************************************************** 
Sub CenterWindow(x,y) 
    Dim iLeft,itop 
    window.resizeTo x, y 
    iLeft = window.screen.availWidth/2 - x/2 
    itop = window.screen.availHeight/2 - y/2 
    window.moveTo ileft, itop 
End Sub 
'***************************************************************** 
Sub OnClickButtonCancel() 
    Window.Close 
End Sub 
'***************************************************************** 
Function DblQuote(strIn) 
    DblQuote = Chr(34) & strIn & Chr(34) 
End Function 
'***************************************************************** 
Sub CreateFolder(strPath) 
    set fso = CreateObject("Scripting.FileSystemObject") 
    If strPath <> "" Then 
     If Not fso.FolderExists(fso.GetParentFolderName(strPath)) then Call CreateFolder(fso.GetParentFolderName(strPath)) 
     fso.CreateFolder(strPath) 
    End If 
End Sub 
'***************************************************************** 
SUB ChangeFondEcran() 
    Dim MyNewWallPaper,NomMyNewWallPaper,NewWallPaperName,WshShell,MonFondEcranBDR,CheminAncienWallpaper,i,MonTab,Destination 
    Set WshShell = CreateObject("WScript.Shell") 
    MonFondEcranBDR = "HKEY_CURRENT_USER\Control Panel\desktop\Wallpaper" 
    CheminAncienWallpaper = WshShell.RegRead(MonFondEcranBDR) 
    MsgBox CheminAncienWallpaper,64,Titre 
'Copie de Sauvegarde de l'ancien Wallpaper 
    Call CopyFile(CheminAncienWallpaper,DossierCourantIMAGE) 
    MyNewWallPaper = fichecran.Value 
    NomMyNewWallPaper = Split(MyNewWallPaper,"\") 
    NewWallPaperName = NomMyNewWallPaper(UBound(NomMyNewWallPaper)) 
    'MsgBox MyNewWallPaper,64,Titre 
    If MyNewWallPaper <> "" Then 
     MonTab = Split(CheminAncienWallpaper,"\") 
     Destination = "" 
     For i = LBound(MonTab) To UBound(MonTab) - 1 
      Destination = Destination + MonTab(i) + "\" 
     Next 
     'MsgBox Destination,64,Titre 
'Supprimer l'ancien Wallpaper 
     Call DeleteMyOldFile(CheminAncienWallpaper) 
     Call CopyFile(MyNewWallPaper,Destination) 
     Call Renommer(Destination & NewWallPaperName,MonTab(UBound(MonTab))) 
     RefreshExplorer() 
    End if 
    Set WshShell = Nothing 
END Sub 
'***************************************************************** 
Function CopyFile(Source,Destination) 
    Dim FSO 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    If FSO.FolderExists(Destination) Then 
     If Right(Destination,1) <> "\" Then 
      Destination = Destination & "\" 
     End if 
     FSO.GetFile(Source).Copy Destination & FSO.GetFileName(Source),True 
     MsgBox "Copie du fond d'écran : " & DblQuote(FSO.GetFileName(Source)) & " dans le dossier " & DblQuote(Destination),64,Titre 
    Else 
     MsgBox DblQuote(Destination) & " n'existe pas !",48,Titre 
    End If 
End Function 
'***************************************************************** 
'Fonction pour écrire le résultat dans un fichier texte 
Sub WriteLog(strText,LogFile) 
    Dim fs,ts 
    Const ForAppending = 8 
    Set fs = CreateObject("Scripting.FileSystemObject") 
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True) 
    ts.WriteLine strText 
    ts.Close 
End Sub 
'***************************************************************** 
Function DeleteMyOldFile(Source) 
    Dim FSO 
    Set FSO = CreateObject("Scripting.FileSystemObject") 
    If FSO.FileExists(Source) Then 
     FSO.GetFile(Source).Delete False 
    End If 
End Function 
'****************************************************************** 
Function Renommer(Fichier1,Fichier2) 
    Dim Ws,Command,Execution 
    Set Ws = CreateObject("WScript.Shell") 
    Command = "Cmd /C Ren "&Fichier1&","&Fichier2&"" 
    Execution = Ws.Run(Command,0,True) 
End Function 
'****************************************************************** 
Sub Kill(Process) 
Dim Ws,Command,Execution 
    Set Ws = CreateObject("WScript.Shell") 
    Command = "cmd /c Taskkill /F /IM "&Process&"" 
    Execution = Ws.Run(Command,0,True) 
End Sub 
'***************************************************************** 
Sub Start(Process) 
Dim Ws,Command,Execution 
    Set Ws = CreateObject("WScript.Shell") 
    Command = "cmd /c Start "&Process&"" 
    Execution = Ws.Run(Command,0,True) 
End Sub 
'***************************************************************** 
Sub RefreshExplorer() 
    Kill("Explorer.exe") 
    Start("Explorer.exe") 
End Sub 
</script> 
<center> 
<B>Veuillez choisir l'image pour changer le fond d'écran </B><br><br> 
<input type="file" size="50" name="fichecran" style="font-weight: bold; id="file1" /> 
<br><br><br> 
<input type="Submit" style="width: 180px" style="font-weight: bold; name="OK" id="OK" value="Changer le fond d'écran" onclick="ChangeFondEcran()"> 
<input type="button" style="width: 100px" style="font-weight: bold; name="Cancel" id="Cancel" value="Sortir" onclick="OnClickButtonCancel"><br><br> 
</body> 
</html>