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

[系统相关] win7下批处理如何根据IP地址最后一段数字更换指定名字的图片做桌面背景/壁纸

本帖最后由 pcl_test 于 2016-6-29 00:08 编辑

实现目标:
50台学生,启动后通过批处理将壁纸更换为带有座位号的图片
座位号与IP地址最后相同,比如192.168.1.101,对应的图片名称是101.bmp
以下代码在xp系统下运行无误,但更换系统为win7后失效,求助大侠们解决在win7系统下实现此功能。
  1. @echo off
  2. color 0a
  3. setlocal enabledelayedexpansion
  4. for /f "tokens=15" %%i in ('ipconfig ^| find /i "ip address"') do set ip=%%i
  5. set ip=!ip:~12,3!
  6. title 正在更换桌面 ...
  7. echo 正在添加注册表项目...
  8. set regadd=reg add "HKEY_CURRENT_USER\Control Panel\Desktop
  9. %regadd%" /v TileWallpaper /d "0" /f
  10. %regadd%" /v Wallpaper /d "c:\3\%ip%.bmp" /f
  11. %regadd%" /v WallpaperStyle /d "2" /f
  12. echo 正在更换桌面背景
  13. RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
  14. exit
复制代码

按电脑名如何?
  1. echo,%COMPUTERNAME%
复制代码
『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

本帖最后由 pcl_test 于 2016-6-29 14:17 编辑

举个栗子
  1. /*&cls
  2. @echo off
  3. set "netpath=%systemroot%\Microsoft.NET\Framework"
  4. for /f "delims=" %%a in ('dir /ad /b "%netpath%\v?.*"') do (
  5.     if exist "%netpath%\%%a\csc.exe" (
  6.         set "cscpath=%netpath%\%%a\csc.exe"
  7.         goto :0
  8.     )
  9. )
  10. echo;未安装.Net Framework 2.0及其上版本组件或相关程序丢失&pause&exit
  11. :0
  12. if not exist "$ChangeWallpaper.exe" (
  13.     "%cscpath%" /out:"$ChangeWallpaper.exe" "%~f0"
  14. )
  15. $ChangeWallpaper.exe "指定桌面背景图片的路径"
  16. pause&exit
  17. */
  18. using System;
  19. using System.IO;
  20. using System.Runtime.InteropServices;
  21. using Microsoft.Win32;
  22. class ChangeWallpaper
  23. {
  24.     [DllImport("user32.dll", EntryPoint = "SystemParametersInfo")]
  25.     public static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);
  26.     static void Main(string[] args)
  27.     {
  28.         if (args.Length<1){
  29.             Console.WriteLine("Usage: $ChangeWallpaper [path]picturename");
  30.         }else{
  31.             if (!File.Exists(args[0])){
  32.                 Console.WriteLine("The specified picture is not exist!");
  33.             }else{
  34.                 string pic = args[0], ext = pic.Substring(pic.LastIndexOf(".")).ToLower();
  35.                 if (ext == ".jpg" || ext == ".bmp" ){
  36.                     string dir = Environment.GetEnvironmentVariable("SystemRoot")+"\\Web\\Wallpaper\\Windows";
  37.                     if (!Directory.Exists(dir))Directory.CreateDirectory(dir);
  38.                     string newpicpath = Path.Combine(dir, Path.GetFileName(pic));
  39.                     try{File.Copy(pic, newpicpath, true);}catch{newpicpath = pic;}
  40.                     if (SystemParametersInfo(20, 1, newpicpath, 0x2) == 0){
  41.                         Console.WriteLine("Setting wallpaper failed!");
  42.                     }else{
  43.                         Registry.CurrentUser.CreateSubKey(@"Control Panel\Desktop\").SetValue("Wallpaper", newpicpath);
  44.                     }
  45.                 }else Console.WriteLine("The format is not supported!");
  46.             }
  47.         }
  48.     }
  49. }
复制代码

TOP

返回列表