Script to copy files depending on the windows version - windows-7

(1st time poster.)
I'm new to coding somewhat and have something I need to script up to place in a GPO. I have shortcuts I want to save to the taskbar. (%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar*.*) The problem is we have both windows 7 and 10 in our domain. All the shortcuts work execpt windows explorer. How do I create a script to where it looks at the windows version and applies the shortcut accordingly? Basically something like:
If version Windows 10 > Copy items in windows 10 shortcuts
or else
If version Windows 7 > Copy items in windows 7 shortcuts
Thanks in advance!
Windows 7 Bat File:
del "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.*" /q
xcopy "\\servername\path\GPOScripts\Shortcuts\Windows 7\*.*" /e /v /y "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" /s /i
regedit.exe /s \\servername\path\GPOScripts\Windows10Settings\PinnedItems.reg
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0 /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0 /f
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer /v EnableAutoTray /t REG_DWORD /d 0 /f
Windows 10:
del "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.*" /q
xcopy "\\servername\path\GPOScripts\Shortcuts\Windows 10\*.*" /e /v /y "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" /s /i
regedit.exe /s \\servername\path\GPOScripts\Windows10Settings\PinnedItems.reg
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0 /f
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\ClassicStartMenu /v {20D04FE0-3AEA-1069-A2D8-08002B30309D} /t REG_DWORD /d 0 /f
reg add HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer /v EnableAutoTray /t REG_DWORD /d 0 /f
Update:
I decided to go the powershell route and do to the following: (It works)
SVersion = (get-itemproperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName).ProductName
if($OSVersion -eq "Windows 10 Pro")
{
Remove-Item "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.*"
Copy-item "\\server\Shortcuts\Windows 10\*.*" -Destination "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" -Recurse
}
ElseIf($OSVersion -eq "Windows 7 Pro")
{
Remove-Item "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\*.*"
Copy-item "\\server\Shortcuts\Windows 7\*.*" -Destination "%appdata%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar" -Recurse

Related

Windows 10 Navigation Pane with Visual Studio

I have a .bat script to add a custom folder to the file explorer navigation pane.
I can see the new extension, OneDrive and GDrive from Microsoft Word. and the default file explorer.
I can't see the new extension or GDrive from Microsoft Visual Studio, but I can see OneDrive and it's own repo folder.
So I think there's some settings in the programs what to show depends on the registry keys.
So I hope there's something key which is missing from the code. Which OneDrive has. :thinking:
:: Step 1: get the uids from here -> https://www.guidgen.com/
#set CLSID=82ca13c3-a60c-46fa-b805-fca6dc0cd75f
#set apperance_name=""
#set icon_path=""
#set folder_path=""
:: Step 1: Add your CLSID and name your extension
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /ve /t REG_SZ /d %apperance_name% >nul 2>&1
:: Step 2: Set the image for your icon
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\DefaultIcon /f /ve /t REG_EXPAND_SZ /d %icon_path% >nul 2>&1
:: Step 3: Add your extension to the Navigation Pane and make it visible
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /v System.IsPinnedToNamespaceTree /t REG_DWORD /d 0x1 >nul 2>&1
:: Step 4: Set the location for your extension in the Navigation Pane
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /v SortOrderIndex /t REG_DWORD /d 0x42 >nul 2>&1
:: Step 5: Provide the dll that hosts your extension.
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\InProcServer32 /f /ve /t REG_EXPAND_SZ /d "%SystemRoot%\system32\shell32.dll" >nul 2>&1
:: Step 6: Define the instance object
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance /f /v CLSID /t REG_SZ /d "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" >nul 2>&1
:: Step 7: Provide the file system attributes of the target folder
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v Attributes /t REG_DWORD /d 0x11 >nul 2>&1
:: Step 8: Set the path for the sync root
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v TargetFolderPath /t REG_EXPAND_SZ /d %folder_path% >nul 2>&1
:: Step 9: Set appropriate shell flags
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\ShellFolder /f /v FolderValueFlags /t REG_DWORD /d 0x28 >nul 2>&1
:: Step 10: Set the appropriate flags to control your shell behavior
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\ShellFolder /f /v Attributes /t REG_DWORD /d 0xF080004D >nul 2>&1
:: Step 11: Register your extension in the namespace root
#reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{%CLSID%} /f /ve /t REG_SZ /d %apperance_name% >nul 2>&1
:: Step 12: Hide your extension from the Desktop
#reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /f /v {%CLSID%} /t REG_DWORD /d 0x1 >nul 2>&1
Okay, I figured it out. This is the whole code for adding into the simple file explorer and to see in another program's file explorer.
To see in a program's file explorer you need to add the same keys into HKEY_CLASSES_ROOT\WOW6432Node\CLSID this.
Watch out! You need to modify the second icon path, because that part can't see the C:\Windows\..etc folder.
After that your cool and ready to go!
:: Step 1: get the uids from here -> https://www.guidgen.com/
:: HKEY_CURRENT_USER\Software\Classes\CLSID\{82ca13c3-a60c-46fa-b805-fca6dc0cd75f}
:: HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{82ca13c3-a60c-46fa-b805-fca6dc0cd75f}
#set CLSID=82ca13c3-a60c-46fa-b805-fca6dc0cd75f
#set apperance_name=""
#set icon_path=""
#set icon_secondpath=""
#set folder_path=""
:: Step 1: Add your CLSID and name your extension
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /ve /t REG_SZ /d %apperance_name% >nul 2>&1
:: Step 2: Set the image for your icon
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\DefaultIcon /f /ve /t REG_EXPAND_SZ /d %icon_path% >nul 2>&1
:: Step 3: Add your extension to the Navigation Pane and make it visible
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /v System.IsPinnedToNamespaceTree /t REG_DWORD /d 0x1 >nul 2>&1
:: Step 4: Set the location for your extension in the Navigation Pane
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%} /f /v SortOrderIndex /t REG_DWORD /d 0x42 >nul 2>&1
:: Step 5: Provide the dll that hosts your extension.
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\InProcServer32 /f /ve /t REG_EXPAND_SZ /d "%SystemRoot%\system32\shell32.dll" >nul 2>&1
:: Step 6: Define the instance object
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance /f /v CLSID /t REG_SZ /d "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" >nul 2>&1
:: Step 7: Provide the file system attributes of the target folder
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v Attributes /t REG_DWORD /d 0x11 >nul 2>&1
:: Step 8: Set the path for the sync root
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v TargetFolderPath /t REG_EXPAND_SZ /d %folder_path% >nul 2>&1
:: Step 9: Set appropriate shell flags
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\ShellFolder /f /v FolderValueFlags /t REG_DWORD /d 0x28 >nul 2>&1
:: Step 10: Set the appropriate flags to control your shell behavior
#reg add HKEY_CURRENT_USER\Software\Classes\CLSID\{%CLSID%}\ShellFolder /f /v Attributes /t REG_DWORD /d 0xF080004D >nul 2>&1
:: Step 11: Register your extension in the namespace root
#reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Desktop\NameSpace\{%CLSID%} /f /ve /t REG_SZ /d %apperance_name% >nul 2>&1
:: Step 12: Hide your extension from the Desktop
#reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\HideDesktopIcons\NewStartPanel /f /v {%CLSID%} /t REG_DWORD /d 0x1 >nul 2>&1
:: It will add a copy of it, so it will appear in programs file explorer like Microsoft Visual Studio
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%} /f /ve /t REG_SZ /d %apperance_name% >nul 2>&1
:: You need to give a different path to this icon, because this part can't see the C:\Windows\...etc
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\DefaultIcon /f /ve /t REG_EXPAND_SZ /d %icon_secondpath% >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%} /f /v System.IsPinnedToNamespaceTree /t REG_DWORD /d 0x1 >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%} /f /v SortOrderIndex /t REG_DWORD /d 0x42 >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\InProcServer32 /f /ve /t REG_EXPAND_SZ /d "%SystemRoot%\system32\shell32.dll" >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\Instance /f /v CLSID /t REG_SZ /d "{0E5AAE11-A475-4c5b-AB00-C66DE400274E}" >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v Attributes /t REG_DWORD /d 0x11 >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\Instance\InitPropertyBag /f /v TargetFolderPath /t REG_EXPAND_SZ /d %folder_path% >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\ShellFolder /f /v FolderValueFlags /t REG_DWORD /d 0x28 >nul 2>&1
#reg add HKEY_CLASSES_ROOT\WOW6432Node\CLSID\{%CLSID%}\ShellFolder /f /v Attributes /t REG_DWORD /d 0xF080004D >nul 2>&1

Windows Cmd Delete Item from HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run

I added an item to startup using the command
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
And after I tryed to delete it with the command :
REG DELETE "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "OMG" /f
But with no succes. I searched for this type of question but with no result. I will realy apreciate any help!
rem ↓↓ missing " double quote
REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
rem ↑↑ missing " double quote
Missing " double quote causes misinterpreting keys as follows:
==> REG ADD HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
The operation completed successfully.
==> reg query "HKCU\Software\Microsoft\Windows\CurrentVersion" /S | findstr /C:"CurrentVersion\Run " 2>NUL
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run /V OMG /t REG_SZ /F /D C:\WGET\wget.exe
==>
Add missing " double quote as follows:
REG ADD "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /V "OMG" /t REG_SZ /F /D "C:\WGET\wget.exe"
Yup, You missed the 'Double Quotes' After REG ADD. But, in this method you are choosing, You need to run the script as an 'Admin'. While, Giving a Batch file Admin Access Can never be a good idea.
So, You can try the alternative of, Copying the Shortcut (the file to Execute at startup) to the path -> "%Userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" - No Admin Needed. :)

(Windows 8.1) Get path of selected folder from custom context menu option

First of all, I have almost no idea about batch language. I'm working on a batch file that writes to the registry in order to add a context menu option that removes "desktop.ini" from the folder from where the context menu option is called. So far, what I got is:
#echo off
#reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings" /t REG_SZ /v "" /d "Reset folder settings" /f
rem #reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command" /t REG_SZ /v "" /d "del /A s h \"%cd%\desktop.ini\" && pause" /f
#reg add "HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command" /t REG_SZ /v "" /d "cmd.exe /c echo \"%~dp0\desktop.ini\" && pause" /f
pause
Which doesn't work because what gets written into the registry is the static folder path from where the installation .bat is called. I'm having quite some trouble finding a solution to this problem so I finally decided I had no choice but to ask for help here.
Use %V to denote the folder from where the context menu option is called.
Hence, the parameters you should use in
reg add "HKCR\Folder\shell\resetFolderSettings\command" ...
could be from a batch script (see that %V should be escaped as %%V):
... /t REG_SZ /v "" /d "%comspec% /c echo \"%%V\desktop.ini\"&&pause" /F
or directly from cmd window - % sign is not escaped here:
... /t REG_SZ /v "" /d "%comspec% /c echo \"%V\desktop.ini\"&&pause" /F
Edit. To make %comspec% expandable as well (and with operational del /A command instead of echo):
... /t REG_EXPAND_SZ /ve /d ^%comspec^%" /c del /A \"%V\desktop.ini\"&pause" /F
used directly from cmd window. See escaped % as ^% (however only those out of double-quoted part of command line) above.
Use another escaping scheme from a batch-script: escape all % as %% how seen in both %%comspec%% and %%V as follows:
... /t REG_EXPAND_SZ /ve /d "%%comspec%% /c del /A \"%%V\desktop.ini\"&pause" /F
Result:
==> reg query "HKCR\Folder\shell\resetFolderSettings\command" /ve
HKEY_CLASSES_ROOT\Folder\shell\resetFolderSettings\command
(Default) REG_EXPAND_SZ %comspec% /c del /A "%V\desktop.ini"&pause

Change registry DisableTaskManager not working in Windows 7

I want to disable a standard user from accessing the task manager. With gpedit.msc this works without problems, but I need to do this from the Windows registry. I already tried assigning 1 to the key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System\DiableTaskMgr, but it is not working.
I use a bat file:
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableTaskMgr /t REG_DWORD /d 1 /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableChangePassword /t REG_DWORD /d 1 /f
taskkill /IM explorer.exe /F

How To Automatically Logon To Windows 7 using a Password

I am working on a Kiosk Application based on Windows 7 Ultimate.
I need:
connect to the kiosk using Remote Desktop Connection (so UserName and
Passwprd seems required).
enable auto login for the kiosk.
Any idea how to achieve these features?
Thanks
It seems you already have your answers, but I'll add something for future readers. This powershell snip allows for auto-logon via the registry.
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultUserName -Value "Administrator"
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name DefaultPassword -Value "Password"
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name AutoAdminLogon -Value 1
Set-ItemProperty -Path 'registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name ForceAutoLogon -Value 1
or can be done the old fashioned way.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"DefaultUserName"="Administrator"
"DefaultPassword"="Password"
"AutoAdminLogon"="1"
"ForceAutoLogon"="1"
The solution to my problem was
Autologon for Windows
http://technet.microsoft.com/en-us/sysinternals/bb963905.aspx
Which enable to automatically login a user using his password
I would also suggest, in order to set Windows configuration for a Kiosk
KIOSK Classic
http://sourceforge.net/projects/kioskclassic/
Copy that to notepad, edit, and save it as a bat file. Run on the destination
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoAdminLogon /t REG_SZ /d 1 /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultUserName /t REG_SZ /d "User" /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword /t REG_SZ /d "Password" /f
reg delete "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v AutoLogonCount /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v ForceUnlockLogon /t REG_DWORD /d 1 /f
reg add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultDomainName /t REG_SZ /d "domain"
If you do not have a domain just use .\
If you want to set a number for the AutoLogonCount, it's decreased on every reboot. Once reached 0, it will stop autologon and reset all your registry keys.

Resources