Can I add an autorun command

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Can I add an autorun command

#1 Post by tweacle » 12 Apr 2018 08:44

Hi

A big big thanks everyone but I have a different question on autorun commands

What im trying to do is use the script below to create folder and move files into new folder but then what im trying to do is add a command that when you open the file after merging it auto opens the associated program thats associated to it.

Sometimes it will need to open Player_Eng.exe OR Nucleus.exe but wont know what one until it tries opening the file as there will be different video types in there. It will not requre both programs to open at once it will always be one or the other.

I used to have an autorun for 1 program when I copied and pasted the files into a folder manually each time by just by copy and paste auto run into folder before burning to disk but now I automated this I donno if there is any way I can automate that too.

Any Ideas or suggestions?

Thanks


Code: Select all

Option Explicit

Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
  Err.Clear
  strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
  If strNewFolder = False Then WScript.Quit
  On Error Resume Next
  objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
  objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&

objWShell.Run "explorer.exe /select,""" & objFSO.BuildPath(strDLFolder, strNewFolder) & """"
Last edited by aGerman on 12 Apr 2018 10:08, edited 1 time in total.
Reason: code formatting

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

Re: Can I add an autorun command

#2 Post by aGerman » 12 Apr 2018 10:08

Sorry but I still don't understand what you're trying to do. The script moves all the files into one folder. But I think that you certainly don't want to open the folder in a certain programm. So I assume it's a file in the folder that you need to pass to those .exe files. It's not clear to me what file it could be.

Steffen

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can I add an autorun command

#3 Post by tweacle » 12 Apr 2018 12:05

Sorry Steffen

Yes you were right in what you said as in moving all the scripts into 1 folder and I do not want to open the folfer in a certain program.

What I was trying to do is click on the folder once all the files are merged , so it opens it up and then looks for either Player_Eng.exe OR Nucleus.exe of which are programs and which ever one it is in there it will launch it.


Does that help?
Glenn

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

Re: Can I add an autorun command

#4 Post by aGerman » 12 Apr 2018 12:19

I assume these are the additional lines you're looking for

Code: Select all

If objFSO.FileExists(objFSO.BuildPath(strNewFolder, "Player_Eng.exe")) Then
  objWShell.Run """" & objFSO.BuildPath(strNewFolder, "Player_Eng.exe") & """"
ElseIf objFSO.FileExists(objFSO.BuildPath(strNewFolder, "Nucleus.exe")) Then
  objWShell.Run """" & objFSO.BuildPath(strNewFolder, "Nucleus.exe") & """"
End If
Steffen

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can I add an autorun command

#5 Post by tweacle » 13 Apr 2018 08:38

Its 90% what I require maybe I was not very clear in explaining.


The code is correct but what im trying to do is to copy the text below into the folder that was created earlier by previous command and then run it automatically when clicking on the folder to open it.

If objFSO.FileExists(objFSO.BuildPath(strNewFolder, "Player_Eng.exe")) Then
objWShell.Run """" & objFSO.BuildPath(strNewFolder, "Player_Eng.exe") & """"
ElseIf objFSO.FileExists(objFSO.BuildPath(strNewFolder, "Nucleus.exe")) Then
objWShell.Run """" & objFSO.BuildPath(strNewFolder, "Nucleus.exe") & """"
End If

Can I do that?

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

Re: Can I add an autorun command

#6 Post by aGerman » 13 Apr 2018 09:12

tweacle wrote:
13 Apr 2018 08:38
... run it automatically when clicking on the folder to open it ...
Can I do that?
Nope. Clicking on a folder can't be linked to a script and things like "autorun.inf" don't work here (only in the root folder of a CD drive).

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can I add an autorun command

#7 Post by tweacle » 13 Apr 2018 09:32

Ok Many Thanks

tweacle
Posts: 71
Joined: 11 Apr 2018 05:38

Re: Can I add an autorun command **AMENDMENT**

#8 Post by tweacle » 02 Jun 2018 06:03

Ladies and Gents

This autorun script runs good but I have a slight problem where as its merging everything in C:\Downloads. Is there anyway that I can set it up to do this command so it merges everything but not
7Z application file types but I do need Player_Eng.exe of which is a application type included into the folder.

Any Ideas.

Code: Select all

Option Explicit

Const strDLFolder = "C:\Downloads"
Dim objFSO, objWShell, objDLFolder, strNewFolder, objFile

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWShell = CreateObject("WScript.Shell")


If Not objFSO.FolderExists(strDLFolder) Then objFSO.CreateFolder(strDLFolder)
objWShell.CurrentDirectory = strDLFolder
Set objDLFolder = objFSO.GetFolder(strDLFolder)
If objDLFolder.Files.Count = 0 Then WScript.Quit

Do
  Err.Clear
  strNewFolder = InputBox("Folder Name", vbLf & "Enter the name of the folder to be created:")
  If strNewFolder = False Then WScript.Quit
  On Error Resume Next
  objFSO.CreateFolder strNewFolder
Loop While Err.Number <> 0 Or Not objFSO.FolderExists(strNewFolder)

On Error Goto 0
For Each objFile In objDLFolder.Files
  objFSO.MoveFile objFile.Name, strNewFolder & "\"
Next

objWShell.Popup "All files moved.", 0, "Done", vbInformation Or vbSystemModal Or &h00040000&

objWShell.Run "explorer.exe /select,""" & objFSO.BuildPath(strDLFolder, strNewFolder) & """"

Post Reply