# Creating a warning message before running a program



## Wimalaya (Dec 22, 2011)

Hello,

i would like to create a warning/reminder message when i open an app.

for example, when i open my music player or something else, i would like to have a reminder popup with ie. a message if i forgot to connect my HDD, before the program opens. (because if it isn't connected, i'll have to rescan the whole thing and that takes a long time..) And then connect the disk, click OK and the program runs.. So as a prevention of these errors, this would be really helpful.

Anyone know a tool that does this?
Not sure if Task Sheduler can do this? i've never used it.

thanks in advance



Tech Support Guy System Info Utility version 1.0.0.2
OS Version: Microsoft Windows 10 Home, 64 bit
Processor: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz, Intel64 Family 6 Model 94 Stepping 3
Processor Count: 8
RAM: 8090 Mb
Graphics Card: NVIDIA GeForce GTX 960M, -2048 Mb
Hard Drives: C: Total - 121327 MB, Free - 23212 MB; D: Total - 953867 MB, Free - 551740 MB; F: Total - 3815317 MB, Free - 1606072 MB;
Motherboard: ASUSTeK COMPUTER INC., GL552VW
Antivirus: Kaspersky Total Security, Updated and Enabled


----------



## Xsage (Jan 8, 2016)

There are proberbly 100 and 1 ways to do this. Personally, I'd opt for a PowerShell script.

See Below:


```
$Path = 'C:\windows\system32\notepad.exe'
$DriveName = "ITS3DM"
if(Get-WmiObject -class win32_logicaldisk -filter "VolumeName='$DriveName'")
{
Start-Process $Path
exit
}
$ws = New-Object -ComObject Wscript.Shell
$ws.Popup("Drive not found, Please connect " + "'" + $DriveName + "'" + " and try again.",0,"Drive not Found!",0x1)
```
Paste that into notepad,
Change the $Path = {string} to the path and program you wish to launch
Change the $DriveName = {string} to the name of the drive when it's plugged in (found in properties, image below)










Don't forget the quotes around the strings.

Save under All Files as a *.ps1 file

Then right click and "Run with powershell" - if you want a simple double click, you can make a simple batch file to point to it through powershell.

Hope this helps,

Xsage


----------



## Wimalaya (Dec 22, 2011)

hi xsage, 

thanks for your response,

i created the .ps1 file with the correct paths and drive name.
it opens fine with powershell.. but how do i use this file now?


----------



## Xsage (Jan 8, 2016)

providing the path is correct, if you right click the .ps1 file and select run with Powershell, it should either present you with a message asking you to attach the drive, or start the program if the drive is already connected.

If it's all working correctly, you should use this instead of the normal shortcut to the application.
If you don't want to right click the file every time I can show you how to make a batch file to run it for you as if its a normal executable.


----------



## Wimalaya (Dec 22, 2011)

ah, right  thanks.
i don't have my drive with me now, so couldn't test it. but will try later or tomorrow..
i'll drop a message after that.
Have a good day

edit:
but what if i open for example an mp3 file without my drive attached and the player opens..? All other entries will still need to be rescanned, right? Any solution for that?


----------



## Xsage (Jan 8, 2016)

What software are you using?


----------



## Wimalaya (Dec 22, 2011)

Does that matter? I didn't want to name it here. It's just about the filetype associated files for a program, i don't think it matters which program. The program will still open and a rescan would be necessary right? Can this be scripted? If it can work for a music player like Foobar or something, it can work for any program i guess.


----------



## Xsage (Jan 8, 2016)

I was thinking perhaps there is a setting somewhere to stop it trying to rescan. What you want is probably possible, but I wouldn't know how to do it without dedicating a lot of time to it.

Maybe someone else has exactly what you are after...


----------



## Wimalaya (Dec 22, 2011)

yes, but i'm using Foobar to give just an example. it's not foobar i want to use for this.

but ok, seems like it will be more complicated? I hope someone can come up with a suitable solution..

edit: 
Just mentioning that the script does work. It's nice, but not exactly what i'm looking for.


----------



## Wimalaya (Dec 22, 2011)

Maybe this thread should be moved to *Software Development*?


----------



## Xsage (Jan 8, 2016)

YAY!

I did it, I was having a fairly long day in the office when I originally answered this. Turns out I wasn't too far off the solution.

So, there are 3 parts to this.

1st we need to make the script which is this: (again all you need to change is Path and DriveName variables)


```
$file = $args[0]
$Path = '"C:\Program Files (x86)\Windows Media Player\wmplayer.exe"'
$DriveName = "ITS3DM"
$qfile = '"' + $file + '"'
if(Get-WmiObject -class win32_logicaldisk -filter "VolumeName='$DriveName'")
{
$qfile
Start-Process -FilePath $Path -ArgumentList $qfile
exit
}
$ws = New-Object -ComObject Wscript.Shell
$ws.Popup("Drive not found, Please connect " + "'" + $DriveName + "'" + " and try again.",0,"Drive not Found!",0x1)
```
save it as a .ps1 and put is somewhere safe

Then we need to make a batch executer for it that will pass on the file name that you click to the script.

go into notepad and paste this: (obviously changing the path to point to the script you just made but be careful not to get rid of the space after .ps1)


```
powershell -command "N:\test.ps1 "%1""
```
Save that as a .bat file.

finally you need to change your default program associations for the .mp3 extension and any other files you wish to be handled like this and point them all to the batch file.

I hope this works for you!


----------



## Wimalaya (Dec 22, 2011)

i tried but didn't work. an error flashes in a cmd window and disappears again.


----------



## Xsage (Jan 8, 2016)

Ugh, seems to be an issue with the way windows 10 handles arguments. - I made it on a Win7 Machine (since that's all we have at work)

Testing in on Windows 10 now, leave it with me.


----------



## Xsage (Jan 8, 2016)

Alright there we go.

Windows 10 feels like a step backwards sometimes...

So all you need to change is the batch file to this (or similar)


```
PowerShell.exe -ExecutionPolicy Bypass -File "C:\Users\Strix\Desktop\Techguy MP3 File Association\script.ps1" %1
```
And as before, change the path

Also I noticed changing file association in Windows 10 isn't straight forward if you want to add a custom program.
In case that will be your next question you should go here:
Control Panel\Programs\Default Programs\Set Associations


----------



## Wimalaya (Dec 22, 2011)

Ha 
That's great, it's working! Thanks a lot Xsage

only one question left: how do i change the .bat icon, so the association files have their original icon back?


----------



## Xsage (Jan 8, 2016)

Good question,
I'm currently PC-less so I can't test things to find out.

You can either try and change the Icon of the batch file via properties and see if that changes for associated files too.
Or I belive there is a way to do it via editing the registry and adding a subkey to the .mp3 key. But I wouldn't recommend doing this unless you are entirely comfortable.

If I find something else, I'll let you know.


----------



## Wimalaya (Dec 22, 2011)

nop, i already tried that before, not possible in properties, i read somewhere to make a shortcut and change that icon but yea it doesn't change all the rest.
don't have much time myself to search around but i try. i'll check out about registry edit.
another thing is i would like to pin it to taskbar aswell, you know, to have a full replacement.. but couldn't figure how to pin it yet.


----------

