[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文本处理] 求助批处理怎样按键选择设置关机时间?

我之前用这个要一个一个来点的,能不能做一个批处理按键选择,求大神帮忙!!!!无尽感激!!!

不知道满足你不

TOP

回复 2# 窄口牛


    感谢大神了,但是这个过程有点复杂呀!我怎么感觉win10系统经常提示不能运行呢?我就算用了管理员模式

TOP

本帖最后由 ivor 于 2020-11-21 16:43 编辑

  1. #&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &exit
  2. #------------------------------------------------------------------------
  3. # Source File Information (DO NOT MODIFY)
  4. # Source ID: 4980ff6f-ceb9-4008-870a-8f1acc1982c8
  5. # Source File: C:\script\1.psf
  6. #------------------------------------------------------------------------
  7. #region File Recovery Data (DO NOT MODIFY)
  8. <#RecoveryData:
  9. iAMAAB+LCAAAAAAABABlk8muo1gQRPeW/A9PtUUqJmOM5HoSGDPPYKYds7GZ72Wwv77crzctda4i
  10. Q6nYRJ6zU2T9UkwvPoHJ10eAuu/+/CJ/47++97uvr7M51VXdJY1QN4WRtMU3/nsA5Rn9n/9zLfRT
  11. +910cYDbZZauB5a9mPyF/Xc4lvcbAEcCY2/3pRAWoK8JIdCUAHQ4co74uhsEfqGPntZncBwlQERY
  12. Uhtziyr7nQY5AVQdJtg9DEqHSfV7motOHKnyQQTBgWDrqzYX5YlYEO9l4SE9l6tiOkxZOfZCAk5v
  13. nmyln7yL/EmLCjxfpTeiJH2ecUJbrFaeZ5DdXpe60gxuZGLZWK1Yj4OtYkU+YEdJnKs+b7tqibjn
  14. ppcs1x7JI+0y+13el1hb4z1t3dboeezNiQkPGIGiMZWjMZ6HkMlQIMnIdrfDV6XAR+tVUJffGza9
  15. seLiYbwcqwJzfQJkv2O4VfUOuh2Yg9SEke4oE1M0VKJ0pFJmfFAVw22chIG9rmZ1ZNRIipOxRyj/
  16. NRyHMo3mhbgNqex01wHsd6TLUMw/leSfSkC2wEejaGg5nU5K5sc0XdZrE2/QIgeCbGOqfKu0pX/W
  17. 2Eey/mnNpi9Tqx9bcU4P+53gxr3vPITtPrmaFWF5ak43j3qRZqnfcQPA0B0B7U5m2KdVRvJ13PMN
  18. Jh/XO7SlW8haLTcpomaLiHzY72pRlfjWv0Q5um2PpAvVd6C9zC6s8qU0ctCB90Lq6tx1Ijk4bvIo
  19. upihQGltjNpfn4Ut8oWvzIgxNvp+F5LXJrz6JeflqePTc7EWg0xA16EHg4scc9OX6FkibJe0Rmjf
  20. yOBwywmfBG+zXTLUR4FOh/ChYDV1TPe7WKZ7jQyTeIrUOQqh5LrmdM0zpAvgAjbYTbWI1iPZnmzH
  21. K9TAWzT+ZfVSHkASD07m5+H/nNEfIH7QYAEo2rSpC/CFfpwz+l/yvv8CaK3F2IgDAAA=#>
  22. #endregion
  23. <#
  24.     .NOTES
  25.     --------------------------------------------------------------------------------
  26.      Code generated by:  SAPIEN Technologies, Inc., PowerShell Studio 2018 v5.5.152
  27.      Generated on:       2020/11/21 16:40
  28.      Generated by:       Administrator
  29.     --------------------------------------------------------------------------------
  30.     .DESCRIPTION
  31.         GUI script generated by PowerShell Studio 2018
  32. #>
  33. #----------------------------------------------
  34. #region Application Functions
  35. #----------------------------------------------
  36. #endregion Application Functions
  37. #----------------------------------------------
  38. # Generated Form Function
  39. #----------------------------------------------
  40. function Show-1_psf {
  41. #----------------------------------------------
  42. #region Import the Assemblies
  43. #----------------------------------------------
  44. [void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
  45. [void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
  46. #endregion Import Assemblies
  47. #----------------------------------------------
  48. #region Generated Form Objects
  49. #----------------------------------------------
  50. [System.Windows.Forms.Application]::EnableVisualStyles()
  51. $form关机时间 = New-Object 'System.Windows.Forms.Form'
  52. $button取消关机 = New-Object 'System.Windows.Forms.Button'
  53. $button20分钟 = New-Object 'System.Windows.Forms.Button'
  54. $button10分钟 = New-Object 'System.Windows.Forms.Button'
  55. $button2小时 = New-Object 'System.Windows.Forms.Button'
  56. $button1小时 = New-Object 'System.Windows.Forms.Button'
  57. $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
  58. #endregion Generated Form Objects
  59. #----------------------------------------------
  60. # User Generated Script
  61. #----------------------------------------------
  62. $form关机时间_Load={
  63. #TODO: Initialize Form Controls here
  64. }
  65. $button1小时_Click={
  66. #TODO: Place custom script here
  67. cmd /c "shutdown /s /t 3600"
  68. }
  69. $button2小时_Click={
  70. #TODO: Place custom script here
  71. cmd /c "shutdown /s /t 7200"
  72. }
  73. $button10分钟_Click={
  74. #TODO: Place custom script here
  75. cmd /c "shutdown /s /t 600"
  76. }
  77. $button20分钟_Click={
  78. #TODO: Place custom script here
  79. cmd /c "shutdown /s /t 1200"
  80. }
  81. $button取消关机_Click={
  82. #TODO: Place custom script here
  83. cmd /c "shutdown /a"
  84. }
  85. # --End User Generated Script--
  86. #----------------------------------------------
  87. #region Generated Events
  88. #----------------------------------------------
  89. $Form_StateCorrection_Load=
  90. {
  91. #Correct the initial state of the form to prevent the .Net maximized form issue
  92. $form关机时间.WindowState = $InitialFormWindowState
  93. }
  94. $Form_Cleanup_FormClosed=
  95. {
  96. #Remove all event handlers from the controls
  97. try
  98. {
  99. $button取消关机.remove_Click($button取消关机_Click)
  100. $button20分钟.remove_Click($button20分钟_Click)
  101. $button10分钟.remove_Click($button10分钟_Click)
  102. $button2小时.remove_Click($button2小时_Click)
  103. $button1小时.remove_Click($button1小时_Click)
  104. $form关机时间.remove_Load($form关机时间_Load)
  105. $form关机时间.remove_Load($Form_StateCorrection_Load)
  106. $form关机时间.remove_FormClosed($Form_Cleanup_FormClosed)
  107. }
  108. catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
  109. }
  110. #endregion Generated Events
  111. #----------------------------------------------
  112. #region Generated Form Code
  113. #----------------------------------------------
  114. $form关机时间.SuspendLayout()
  115. #
  116. # form关机时间
  117. #
  118. $form关机时间.Controls.Add($button取消关机)
  119. $form关机时间.Controls.Add($button20分钟)
  120. $form关机时间.Controls.Add($button10分钟)
  121. $form关机时间.Controls.Add($button2小时)
  122. $form关机时间.Controls.Add($button1小时)
  123. $form关机时间.AutoScaleDimensions = '6, 13'
  124. $form关机时间.AutoScaleMode = 'Font'
  125. $form关机时间.ClientSize = '264, 128'
  126. $form关机时间.Name = 'form关机时间'
  127. $form关机时间.Text = '关机时间'
  128. $form关机时间.add_Load($form关机时间_Load)
  129. #
  130. # button取消关机
  131. #
  132. $button取消关机.Location = '96, 69'
  133. $button取消关机.Name = 'button取消关机'
  134. $button取消关机.Size = '64, 27'
  135. $button取消关机.TabIndex = 4
  136. $button取消关机.Text = '取消关机'
  137. $button取消关机.UseCompatibleTextRendering = $True
  138. $button取消关机.UseVisualStyleBackColor = $True
  139. $button取消关机.add_Click($button取消关机_Click)
  140. #
  141. # button20分钟
  142. #
  143. $button20分钟.Location = '21, 69'
  144. $button20分钟.Name = 'button20分钟'
  145. $button20分钟.Size = '51, 27'
  146. $button20分钟.TabIndex = 3
  147. $button20分钟.Text = '20分钟'
  148. $button20分钟.UseCompatibleTextRendering = $True
  149. $button20分钟.UseVisualStyleBackColor = $True
  150. $button20分钟.add_Click($button20分钟_Click)
  151. #
  152. # button10分钟
  153. #
  154. $button10分钟.Location = '173, 23'
  155. $button10分钟.Name = 'button10分钟'
  156. $button10分钟.Size = '51, 27'
  157. $button10分钟.TabIndex = 2
  158. $button10分钟.Text = '10分钟'
  159. $button10分钟.UseCompatibleTextRendering = $True
  160. $button10分钟.UseVisualStyleBackColor = $True
  161. $button10分钟.add_Click($button10分钟_Click)
  162. #
  163. # button2小时
  164. #
  165. $button2小时.Location = '96, 23'
  166. $button2小时.Name = 'button2小时'
  167. $button2小时.Size = '51, 27'
  168. $button2小时.TabIndex = 1
  169. $button2小时.Text = '2小时'
  170. $button2小时.UseCompatibleTextRendering = $True
  171. $button2小时.UseVisualStyleBackColor = $True
  172. $button2小时.add_Click($button2小时_Click)
  173. #
  174. # button1小时
  175. #
  176. $button1小时.Location = '21, 23'
  177. $button1小时.Name = 'button1小时'
  178. $button1小时.Size = '51, 27'
  179. $button1小时.TabIndex = 0
  180. $button1小时.Text = '1小时'
  181. $button1小时.UseCompatibleTextRendering = $True
  182. $button1小时.UseVisualStyleBackColor = $True
  183. $button1小时.add_Click($button1小时_Click)
  184. $form关机时间.ResumeLayout()
  185. #endregion Generated Form Code
  186. #----------------------------------------------
  187. #Save the initial state of the form
  188. $InitialFormWindowState = $form关机时间.WindowState
  189. #Init the OnLoad event to correct the initial state of the form
  190. $form关机时间.add_Load($Form_StateCorrection_Load)
  191. #Clean up the control events
  192. $form关机时间.add_FormClosed($Form_Cleanup_FormClosed)
  193. #Show the Form
  194. return $form关机时间.ShowDialog()
  195. } #End Function
  196. #Call the form
  197. Show-1_psf | Out-Null
复制代码
#&cls&@powershell "Invoke-Expression ([Io.File]::ReadAllText('%~0',[Text.Encoding]::UTF8))" &pause&exit

TOP

我这个批处理需要放到“timing定时”文件夹内,并且文件夹内的批处理文件不能改名,否则会出错。
  1. @echo off
  2. cls
  3. echo 定时关机
  4. echo ===============================
  5. echo 1.10分钟后关机
  6. echo 2.20分钟后关机
  7. echo 3.30分钟后关机
  8. echo 4.1小时后关机
  9. echo 5.2小时后关机
  10. echo 6.取消关机
  11. echo ===============================
  12. set /p v=请选择:
  13. if "%v%"=="1" 10分钟后关机
  14. if "%v%"=="2" 20分钟后关机
  15. if "%v%"=="3" 30分钟后关机
  16. if "%v%"=="4" 1小时后关机
  17. if "%v%"=="5" 2小时后关机
  18. if "%v%"=="6" 取消关机
复制代码

TOP

返回列表