Archive

Posts Tagged ‘Windows’

DIR命令无法获得精确到秒的问题

July 5th, 2021 No comments

DIR命令无法获得精确到秒的问题

方法一,dir命令只能到分钟,如果需要到秒,建议改用forfiles命令

REM "delims=" is required to avoid stripping AM/PM
for /f "delims=" %%i in ('"forfiles /p C:\Users\limc /m *.bat /c "cmd /c echo @fdate @ftime" "') do set modif_time=%%i
echo %modif_time%

参考
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/cc753551(v=ws.11)?redirectedfrom=MSDN

方法二,用VBS的FileSystemObject方式解决

@set @n=0/*&echo off
dir /a-d/s/b|Cscript -nologo -e:jscript "%~f0" > 1.txt
pause&exit /b */
var fso=new ActiveXObject('scripting.FileSystemObject');
while(!WSH.StdIn.AtEndOfStream)
{
file=fso.GetFile(WSH.StdIn.ReadLine());
t=new Date(file.DateCreated);
t1 = t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate() + " " + t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
WSH.Echo(file + "\t" + t1);
}
Categories: 零敲碎打 Tags: , ,

windows计划任务指定时间段执行程序

July 5th, 2021 No comments

一个简单的需求,windows服务器设置计划任务,在需要在指定时间段9点到15点执行特定的程序。
但是windows的计划任务不像corntab那样支持设定指定时间区间,只可以设置每小时启动一次。

方法1.启动Bootstrap程序,根据当前时间决定是否继续执行任务

获取当前时间的字符串

SET curr_time=%TIME:~0,-5%
SET curr_time_str=%curr_time::=%

获取时间后,逻辑判断是否goto执行相应的代码

完整的代码

@echo off
ECHO "Time Schedule Bootstrap"
SET curr_time=%TIME:~0,-5%
SET curr_time_str=%curr_time::=%
IF %curr_time_str% leq 0900 (GOTO time_cancel) ELSE (
IF %curr_time_str% leq 1500 (GOTO time_exec) ELSE (
GOTO time_cancel
)
)
exit 0
 
:time_exec
ECHO "Call CMD.exe"
CMD.exe 
exit 0
 
:time_cancel
ECHO "Canceled"
exit 10

方法2.设置每天启动一次在指定的小时,需要设置多次,此处跳过

Categories: 系统管理 Tags: ,

Win10 DISM离线安装.net framework

June 16th, 2020 No comments

Win10 DISM离线安装.net framework

DISM(Deployment Image Servicing and Management)就是部署映像服务和管理 (DISM.exe) 用于安装、卸载、配置和更新脱机 Windows(R) 映像和脱机 Windows 预安装环境 (Windows PE) 映像中的功能和程序包。

安装.net framework, windows系统安装盘位置为E:盘

Dism /Online /Enable-Feature /FeatureName:netfx3 /Source:E:\sources\sxs

其他用途

1.扫描映像,查看映像是否有损坏(有损坏时电脑会遇到许多小问题,比如可能无法更新系统)

Dism /Online /Cleanup-Image /ScanHealth

2.最后是修复系统映像文件

Dism /Online /Cleanup-Image /RestoreHealth

使用本地源修复镜像,可以是windows安装光盘,或者虚拟光驱加载ISO文件

Dism /Online /Cleanup-Image /RestoreHealth /Source:c:\test\mount\windows /LimitAccess

PE环境下也可以用ImageFile方式,直接使用windows image格式文件

Dism /Apply-Image /ImageFile:X:sourcesinstall.wim /Index:1 /ApplyDir:C:

参考
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/what-is-dism

Categories: 系统管理 Tags: ,

windows右键快速创建功能按键

November 9th, 2018 No comments

每天都需要在同一个目录下建立当日日期命名的文件夹,
就偷懒想把这个功能做到WINDOWS的右键。

STEP1.新建一个.reg文件,写入以下内容

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\Directory\Background\Shell\CMD_NAME]
"MUIVerb"="日期文件夹"
"Icon"="shell32.dll,3"
"Position"="top"
 
[HKEY_CLASSES_ROOT\Directory\Background\Shell\CMD_NAME\command]
@=“COMMAND”

Read more…

Categories: 系统管理 Tags: ,

Windows Server 2012 GUI与Core的切换

December 19th, 2016 No comments

使用Hyper-V方案对服务器进行虚拟化实验,为了节省时间和提高安全性,安装Windows Server 2012 时直接安装成Microsoft Server 2012 Core。安装完毕后只有一个cmd命令提示符可以用。服务器管理各种不方便,考虑切换为GUI模式后再切换为Core模式。

切换GUI模式需要手动安装Windows Server的GUI组件
Server-Gui-Mgmt-Infra
Server-Gui-Shell
使用
Install-WindowsFeature
Uninstall-WindowsFeature
命令即可完成Windows功能的安装和删除

Read more…

w_char*和char *转换宽窄字符

June 29th, 2016 No comments

w_char*和char*在windows编程过程中进行转换是经常需要的,通常由互联网我们取到都是utf-8编码,到windows应用程序里面却需要用unicode编码。
一开始用stdlib.h 下wcstombs_s和mbstowcs_s的代码实现,发现总是转换失败和出错。
char 转 WCHAR 、wchar_t、LPWSTR ,窄字符转宽字符,C++代码

//+------------------------------------------------------------------+
//| char to WCHAR 、wchar_t、LPWSTR etc                              |
//+------------------------------------------------------------------+
static char* WStr2CStr(const wchar_t* WStr)
  {
             // 长度设置
              size_t len = wcslen(WStr) + 1;
              size_t converted = 0;
              // 准备转换的对象
              char *CStr;
              CStr=(char*)malloc(len*sizeof(char));
              // 转换
              wcstombs_s(&converted, CStr, len, WStr, _TRUNCATE);
              // 返回
              return CStr;
  }

Read more…

Categories: 语言编程, 零敲碎打 Tags: , ,

Windows下实现Deamon守护脚本

June 28th, 2016 No comments

最近需要在Windows服务器上保持程序长期允许,因为程序比较老,无法用srvany.exe 改写成windows服务,只能自己手动编写守护脚本实现,网上找了短比较靠谱的守护脚本,在此mark一下。支持监视进程、端口。

守护脚本定义部分

@echo off
 
::检测时间间隔,单位:秒
set _interval=5
 
::需要守护的进程名称
set _processName=ProcessName
 
::需要守护的进程启动命令
set _processCmd=C:\xxxx.exe
 
::需要守护的进程预估启动完毕所需时间,单位:秒
set _processTimeout=10
 
::需要守护的进程所监听的端口
set _port=8080
 
::进程用户名,一般是Administrator
set _username=Administrator

Read more…

Categories: 零敲碎打 Tags: , ,