Calling system command from batch

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rolypoly2308
Posts: 2
Joined: 16 Jun 2012 16:32

Calling system command from batch

#1 Post by rolypoly2308 » 16 Jun 2012 16:40

I am making an installation batch program where it copies the files into the correct folders and then runs a registry file to give them the correct icon. Although I need to find a way to call, I believe SHCNE_ASSOCCHANGED from SHChangeNotify API so that it can update the icon. Help much appreciated :wink:

aGerman
Expert
Posts: 4741
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Calling system command from batch

#2 Post by aGerman » 17 Jun 2012 17:05

It's true that you could update file type icons using SHChangeNotify API but unfortunately you can't call it directly from a batch file. You need a programming language to compile a 3rd party application where that API is called.

Not sure if the following would help. If you've got installed the .NET framework then you should have csc.exe on board. It's a C# compiler.
Try that ugly combination of batch and C# code to compile your own refresh tool.

refresh.bat (all in one file):

Code: Select all

/* &@cls
:: Batch code:
@echo off

for /f "delims=" %%i in ('dir /a-d /b /s "%SystemRoot%\Microsoft.NET\Framework\csc.exe" 2^>nul') do set "csc=%%i"
if not defined csc (
  echo "csc.exe" not found, compiling impossible.
  pause>nul
  goto :eof
)
call "%csc%" /nologo /target:exe /out:"%~dpn0.exe" "%~f0"

:: call "%~dpn0.exe"
:: del "%~dpn0.exe"
pause
goto :eof

:: C# code:
*/
using System;
using System.Runtime.InteropServices;

class Program
{
  [DllImport("shell32.dll", CharSet = CharSet.Auto)]
  private static extern void SHChangeNotify(long wEventId, uint uFlags, IntPtr dwItem1, IntPtr dwItem2);
  private const long SHCNE_ASSOCCHANGED = 0x08000000;
  private const uint SHCNF_IDLIST       = 0x0000;

  static void Main(string[] args)
  {
    SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, IntPtr.Zero, IntPtr.Zero);
  }
}

Regards
aGerman

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Calling system command from batch

#3 Post by Squashman » 17 Jun 2012 19:34

Why not use something like NSIS instead.
http://nsis.sourceforge.net/Main_Page

rolypoly2308
Posts: 2
Joined: 16 Jun 2012 16:32

Re: Calling system command from batch

#4 Post by rolypoly2308 » 20 Jun 2012 17:41

Thanks, I will try both methods and see which one is easier/more fitting :)

Post Reply