标题: [系统相关] win7下批处理如何根据IP地址最后一段数字更换指定名字的图片做桌面背景/壁纸 [打印本页]
作者: gzzcz 时间: 2016-6-28 09:37 标题: win7下批处理如何根据IP地址最后一段数字更换指定名字的图片做桌面背景/壁纸
本帖最后由 pcl_test 于 2016-6-29 00:08 编辑
实现目标:
50台学生,启动后通过批处理将壁纸更换为带有座位号的图片
座位号与IP地址最后相同,比如192.168.1.101,对应的图片名称是101.bmp
以下代码在xp系统下运行无误,但更换系统为win7后失效,求助大侠们解决在win7系统下实现此功能。- @echo off
- color 0a
- setlocal enabledelayedexpansion
- for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set ip=%%i
- set ip=!ip:~12,3!
- title 正在更换桌面 ...
- echo 正在添加注册表项目...
- set regadd=reg add "HKEY_CURRENT_USER\Control Panel\Desktop
- %regadd%" /v TileWallpaper /d "0" /f
- %regadd%" /v Wallpaper /d "c:\3\%ip%.bmp" /f
- %regadd%" /v WallpaperStyle /d "2" /f
- echo 正在更换桌面背景
- RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
- exit
复制代码
作者: yu2n 时间: 2016-6-28 20:12
按电脑名如何?复制代码
作者: pcl_test 时间: 2016-6-29 13:43
本帖最后由 pcl_test 于 2016-6-29 14:17 编辑
举个栗子- /*&cls
- @echo off
- set "netpath=%systemroot%\Microsoft.NET\Framework"
- for /f "delims=" %%a in ('dir /ad /b "%netpath%\v?.*"') do (
- if exist "%netpath%\%%a\csc.exe" (
- set "cscpath=%netpath%\%%a\csc.exe"
- goto :0
- )
- )
- echo;未安装.Net Framework 2.0及其上版本组件或相关程序丢失&pause&exit
- :0
- if not exist "$ChangeWallpaper.exe" (
- "%cscpath%" /out:"$ChangeWallpaper.exe" "%~f0"
- )
- $ChangeWallpaper.exe "指定桌面背景图片的路径"
- pause&exit
- */
- using System;
- using System.IO;
- using System.Runtime.InteropServices;
- using Microsoft.Win32;
- class ChangeWallpaper
- {
- [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
- public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
- static void Main(string[] args)
- {
- if (args.Length<1){
- Console.WriteLine("Usage: $ChangeWallpaper [path]picturename");
- }else{
- if (!File.Exists(args[0])){
- Console.WriteLine("The specified picture is not exist!");
- }else{
- string pic = args[0], ext = pic.Substring(pic.LastIndexOf(".")).ToLower();
- if (ext == ".jpg" || ext == ".bmp" ){
- string dir = Environment.GetEnvironmentVariable("SystemRoot")+"\\Web\\Wallpaper\\Windows";
- if (!Directory.Exists(dir))Directory.CreateDirectory(dir);
- string newpicpath = Path.Combine(dir, Path.GetFileName(pic));
- try{File.Copy(pic, newpicpath, true);}catch{newpicpath = pic;}
- if (SystemParametersInfo(20, 1, newpicpath, 0x2) == 0){
- Console.WriteLine("Setting wallpaper failed!");
- }else{
- Registry.CurrentUser.CreateSubKey(@"Control Panel\Desktop\").SetValue("Wallpaper", newpicpath);
- }
- }else Console.WriteLine("The format is not supported!");
- }
- }
-
- }
- }
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |