सम्बन्ध कि रीव्स पोस्ट एक बनाने के लिए नेतृत्व किया .ps1
साथ फाइल करें यह स्क्रिप्ट इसके अंदर। विंडोज पावर शेल में इस नई फ़ाइल को चलाने से बैकग्राउंड इमेज की ओर इशारा करते हुए फाइल एक्सप्लोरर खुल गया। मुझे बदलना पड़ा ExecutionPolicy
PS .ps1 फ़ाइलों को चलाने के लिए अनुमति देने के लिए।
हालाँकि, हर बार पीएस खोलना और फिर चलने की आज्ञा मेरे लिए एक परेशानी से अधिक थी, इसलिए मैं इस एसओ पोस्ट को पढ़ें और मेरे डेस्कटॉप पर एक शॉर्टकट बनाया जिसका एक लक्ष्य था
powershell.exe -command "& 'C:\A path to the new ps1 file\MyScript.ps1'"
यहां लिपि की एक कॉपी का उपयोग किया गया है .ps1 मामले में लिंक नीचे जाता है:
Try
{
# Get script name
$ScriptName=(Get-Item $PSCommandPath).Name
# Load Windows Forms and initialize visual styles
# Not needed for Windows 8. But I still don't know whether it is running on Windows 8.
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Application]::EnableVisualStyles()
# Check Windows verison
$vers=[System.Environment]::OSVersion.Version
If (!(($vers.Major -eq 6) -and ($vers.Minor -ge 2) -and ($vers.Minor -le 3))) {
$result=[System.Windows.Forms.MessageBox]::Show("This operating system is not supported. This script only supports Windows NT 6.2 or 6.3. (i.e. Windows 8, Windows Server 2012, Windows 8.1 or Windows Server 2012 R2). You seem to be running:`r`r"+[System.Environment]::OSVersion.VersionString, "Script", "OK", "Error");
break;
}
# Initialize counters
$Path_Start_Delta=24 #The offset at which the image path starts
$Path_End_Delta=-1 #The offset at which the image path ends... is still unknown
# First, access Windows Registry and get the property containing wallpaper path
try {
$TranscodedImageCache=(Get-ItemProperty 'HKCU:\Control Panel\Desktop' TranscodedImageCache -ErrorAction Stop).TranscodedImageCache
}
catch [System.Management.Automation.ItemNotFoundException],[System.Management.Automation.PSArgumentException] {
$result=[System.Windows.Forms.MessageBox]::Show("Windows does not seem to be holding a record of a wallpaper at this time.`r`r"+$Error[0].Exception.Message,"Script","OK","Error");
break;
}
# Decode the property containing the path
# First, let's assume the path ends at the last byte of $TranscodedImageCache
$Path_End_Delta=$TranscodedImageCache.length-1
# A sequence of 0x00 0x00 marks the end of string. Find it.
# The array that we are searching contains a UTF-16 string. Each character is a little-endian WORD,
# so we can search the array's even indexes only.
for ($i = $Path_Start_Delta; $i -lt ($TranscodedImageCache.length); $i += 2) {
if ($TranscodedImageCache[($i+2)..($i+3)] -eq 0) {
$Path_End_Delta=$i + 1;
Break;
}
}
# Convert the bytes holding the wallpaper path to a Unicode string
$UnicodeObject=New-Object System.Text.UnicodeEncoding
$WallpaperSource=$UnicodeObject.GetString($TranscodedImageCache[$Path_Start_Delta..$Path_End_Delta]);
# Test item's existence
Get-Item $WallpaperSource -Force -ErrorAction Stop | Out-Null
# Wallpaper should by now have been found.
# Present it to the user. If he so chooses, launch Explorer to take him were wallpaper is.
$result=[System.Windows.Forms.MessageBox]::Show("Wallpaper location: `r$WallpaperSource`r`rLaunch Explorer?", "Script", "YesNo", "Asterisk");
if ($result -eq "Yes")
{
Start-Process explorer.exe -ArgumentList "/select,`"$WallpaperSource`""
}
}
Catch
{
$result=[System.Windows.Forms.MessageBox]::Show("Error!`r`r"+$Error[0], "Script", "OK", "Error");
break;
}