我正在写一个脚本:
1. 检测它在哪个操作系统上运行,win10 还是 win8(只有这两个选项)
2. 执行三项查找和替换-actions
3. 启动属于它的程序。
下面是一个尝试的 CMD/DOS 批处理脚本:
01 set %versionOS% to ver
REM in the above line I want to fill a variable called
REM %versionOS% with the output of the ver commmand
02 IF %versionOS% = "Microsoft Windows [Version 10.0.14393]"
REM in the above line I check if variable
REM %versionOS% equals "Microsoft Windows [Version 10.0.14393]"
03 command to close an application.
REM in the above line I want to close an application
REM c:\path\WinCmd.exe this line could be the 1st line too, yes
04 goto Win10
05 *commmands that change wincmd.ini to one that's suited for Win8
06 (I've figured this one out already)*
07 goto ProgStart
08 :Win10
09 *commmands that change wincmd.ini to one that's suited for Win10*
10
11 :ProgStart
12 c:\path\WinCmd.exe
我需要帮助来理解前三行。谢谢。
答案1
就像卖房子一样,最重要的三件事是位置,位置,位置,在回答问题时,最重要的三件事是动机、动机、动机...显然。这是我的解决方案,效果非常好。欢迎评论,一切都有待改进。<3 <3 <3
taskkill /im TOTALCMD64.EXE
IF %USERDOMAIN% == GwenKillerby goto Win10
echo win8
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'D\:\\', 'QzQ' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'C\:\\', 'D:\' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'QzQ', 'C:\' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace '\\', '\' } | Set-Content f:\totalcmd852\wincmd.ini"
goto ProgStart
:Win10
echo win10
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'C\:\\', 'QzQ' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'D\:\\', 'C:\' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace 'QzQ', 'D:\' } | Set-Content f:\totalcmd852\wincmd.ini"
powershell -Command "(Get-Content f:\totalcmd852\wincmd.ini) | ForEach-Object { $_ -replace '\\', '\' } | Set-Content f:\totalcmd852\wincmd.ini"
:ProgStart
f:\totalcmd852\TOTALCMD64.EXE
(顺便说一句:如果有人能告诉我为什么在'C\:\\', 'D:\'
“C”中需求两个斜线,而对于“D”,一个就足够了,我会很高兴。)
首先,我尝试通过 tmpfile 使其取决于 Windows 版本,这是一种更优雅、更强大的方式。
rem VER > tmpFile
rem set /p myvar= < tmpFile
rem del tmpFile
但我无法让它工作,所以我使用了 UserWhatever。此外,版本在 Win10 和 Win8 中几乎完全相同:微软 Windows [6.xxx]相对 微软 Windows [10.xxx],这意味着要处理那些令人毛骨悚然的标记,brrrr!
我愿意接受任何行数更少或更简单的解决方案。或者,你知道,一个完整的 PS 脚本/batfile... ;) ;) ;)