Board logo

標題: [Windows 10] How to run script when user click shutdown? [打印本頁]

作者: banang    時間: 2020-10-11 00:33     標題: How to run script when user click shutdown?

本帖最後由 banang 於 2020-10-11 00:34 編輯

各位師兄,

請問如何 run script when user click shutdown ?

I try the following under Local Group Policy but the the script fails to run.

Motherboard: Asrock B450M-HDV 4.0
Windows 10 Pro 2004
Shutdown script.gif

圖片附件: Shutdown script.gif (2020-10-11 00:32, 38.92 KB) / 下載次數 66
https://h2.hkepc.com/forum/attachment.php?aid=2223595&k=35b3ed27eb7ca6287fc3fbb8bd84c4ab&t=1781456689&sid=1NGF2IhqlG


作者: tunster    時間: 2020-10-11 00:38

要知你 run 啲乜同出咩 error
作者: banang    時間: 2020-10-11 11:12

回覆 2# tunster

Below are the commands of the script file:

ipconfig /displaydns > h:\script\displaydns.txt
for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "displaydns.txt" %%e-%%f-%%g.txt
作者: 觀星是答案    時間: 2020-10-11 13:42

回覆  tunster

Below are the commands of the script file:

ipconfig /displaydns > h:\script\display ...
banang 發表於 2020-10-11 11:12

你個 h drive 係 network drive 定本機 ?
你有無試下用簡單 d 既 command , 再 save 係本機去確認 shutdown script 有無正常 run 到 , 慢慢再排除問題 ?

e.g.
echo Testing > C:\Test\test.txt

當然你係個 C Drive 要開定個 "Test" folder 先
作者: banang    時間: 2020-10-12 10:19

師兄,

h: is just one of the local drive in a local SSD.

Simple commands like PAUSE or ECHO doesn't seem to work. No pause, no echo, no file created from piping to > local drive.
作者: 觀星是答案    時間: 2020-10-12 12:17

本帖最後由 觀星是答案 於 2020-10-12 12:23 編輯
師兄,

h: is just one of the local drive in a local SSD.

Simple commands like PAUSE or ECHO doesn' ...
banang 發表於 2020-10-12 10:19

Permission 有無試 set 做 everyone full access ?
作者: 觀星是答案    時間: 2020-10-12 12:38

我直接將個 shutdown script 放係 default 既 scrip folder , 直接 run (唔用 cmd /c) , 可以成功行到

Untitled.png

圖片附件: Untitled.png (2020-10-12 12:37, 12.38 KB) / 下載次數 47
https://h2.hkepc.com/forum/attachment.php?aid=2223965&k=0a19051501b653b30e8f283085e47ba0&t=1781456689&sid=1NGF2IhqlG


作者: tunster    時間: 2020-10-12 13:23

你個 script 放 system32, 你肯定你有 permission?

試下放 C:\temp 哩啲無咁密嘅 folder 試下啲簡單 command 先
作者: wunit    時間: 2020-10-12 14:18

你要的可能係logoff script而唔係shutdown script
作者: banang    時間: 2020-10-13 20:19

回覆 8# tunster
師兄,

I use local admin, to keep it simple, I put it in local folder C:\temp. Run it manually, no problem.

Somehow it still doesn't work during after I click shutdown.
Shutdown local script.gif

圖片附件: Shutdown local script.gif (2020-10-13 20:18, 38.21 KB) / 下載次數 46
https://h2.hkepc.com/forum/attachment.php?aid=2224369&k=c6165116d5774a8deff89426e855e1d1&t=1781456689&sid=1NGF2IhqlG


作者: tunster    時間: 2020-10-13 21:28

試下熄佐 Fast Startup
作者: waishingme    時間: 2020-10-14 01:15

本帖最後由 waishingme 於 2020-10-14 01:18 編輯

如果user logoff 行scripts都達到目的,就喺user logoff 行
有時可能係UAC 關係,要再研究點樣轉user privilege / account去execute





歡迎光臨 電腦領域 HKEPC Hardware (https://h2.hkepc.com/forum/) Powered by Discuz! 7.2