Welcome to MSFN

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.


Sign in to follow this  
Followers 0
clivebuckwheat

Need help to change the default program for .java files

13 posts in this topic

Hi

I have to change the default program for .java files it should open by default in a program called Ready to Program which is available here. http://compsci.ca/holtsoft/ready171_install.exe

I tried the following vbs script but it isn't working.Any help would be greatly appreciated as I have to make this the default on about 250 computers,

Option Explicit
Dim objShell
set objShell = WScript.CreateObject ("WScript.Shell")

addFileAssociation ".java", "C:\Program Files (x86)\Ready to Program\Ready.exe"

Sub addFileAssociation( fileExt, whichApp )
If ( Left(fileExt, 1) <> "." ) Then
fileExt = "." & fileExt
End If
objShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\" & fileExt & "\Application", whichApp
End Sub

0

Share this post


Link to post
Share on other sites

Where did you get that snippet?

Particularly, where did you get the Registry path?

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\

Any reason NOT to use the ASSOC/FTYPE/ASSOCIATE commands? :unsure:

http://ss64.com/nt/assoc.html

http://ss64.com/nt/ftype.html

http://ss64.com/nt/associate.html

jaclaz

I got the code from stack over flow. here is the snippet of code.

http://stackoverflow.com/questions/7988655/proper-way-tho-change-file-associations-using-vbs

I have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers.

0

Share this post


Link to post
Share on other sites

I have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers.

Try these:

http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/27/quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-03-27-09.aspx

ListFileAssociations.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, True

ChangeFileAssociation.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, True

Afaik, a file association has a number of related keys in HKEY_CLASSES_ROOT (that the built-in commands know how to manage).

The snippet you posted most probably originated (without credits) from here:

http://jimkeller.blogspot.it/2005/09/changing-file-associations-in-windows.html

Which BTW "justifies" the otherwise senseless:

If ( Left(fileExt, 1) <> "." ) Then

fileExt = "." & fileExt

End If

If you hardcoded .java, there is no need to check if the first character is a dot.... ;)

This might be useful to quickly check associations:

http://www.nirsoft.net/utils/file_types_manager.html

jaclaz

0

Share this post


Link to post
Share on other sites

I have never had any luck with the assoc commands, and I would like to use vbs, so I could just append the file associate fix into my default printer.vbs that runs in the startup of all the computers.

Try these:

http://blogs.technet.com/b/heyscriptingguy/archive/2009/03/27/quick-hits-friday-the-scripting-guys-respond-to-a-bunch-of-questions-03-27-09.aspx

ListFileAssociations.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K Assoc | more"), 1, True

ChangeFileAssociation.vbs

Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype TIFImage.Document =""C:\Program Files\MSPVIEW.exe"" ""%1"""), 1, True

Afaik, a file association has a number of related keys in HKEY_CLASSES_ROOT (that the built-in commands know how to manage).

The snippet you posted most probably originated (without credits) from here:

http://jimkeller.blogspot.it/2005/09/changing-file-associations-in-windows.html

Which BTW "justifies" the otherwise senseless:

If ( Left(fileExt, 1) <> "." ) Then

fileExt = "." & fileExt

End If

If you hardcoded .java, there is no need to check if the first character is a dot.... ;)

This might be useful to quickly check associations:

http://www.nirsoft.net/utils/file_types_manager.html

jaclaz

Thanks Jaclaz,

You are saying to do this, i am sorry I am really not skilled in vbs. Do this

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Edited by clivebuckwheat
0

Share this post


Link to post
Share on other sites

You need a newline:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

This snippet assumes that a filetype "java.Document" already exists (and is associated to the .java extension)

jaclaz

0

Share this post


Link to post
Share on other sites

Thank Jaclaz,

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Unfortunately the above still refuses to change, the .java extension to open in Ready to Program.

Edited by clivebuckwheat
0

Share this post


Link to post
Share on other sites

Jaclaz,

I did an assoc .java

it seems there is no association for the .java extension, so that is why the above vbs script will not work. How can I make the .java association exist first?

Thanks for the help. I really do appreciated.

0

Share this post


Link to post
Share on other sites

How can I make the .java association exist first?

Using ASSOC ! :realmad: back to square #1, actually post #2 (and given links).

assoc .java=java.Document

This should do :unsure:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

jaclaz

0

Share this post


Link to post
Share on other sites

How can I make the .java association exist first?

Using ASSOC ! :realmad: back to square #1, actually post #2 (and given links).

assoc .java=java.Document

This should do :unsure:

Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

jaclaz

Thank you Jaclaz it now changes the association, I could have swore I ran the assoc command. Sorry. One more question about the above vbscript. Would it be possible to suppress the cmd window?. I need it totally silent as I am going to put it in the startup of my computers.

Thanks again you been an amazing help.

0

Share this post


Link to post
Share on other sites

Thank you Jaclaz it now changes the association, I could have swore I ran the assoc command. Sorry. One more question about the above vbscript. Would it be possible to suppress the cmd window?. I need it totally silent as I am going to put it in the startup of my computers.

Thanks again you been an amazing help.

Which brings us back to square #1 on a few other thread :w00t:

Use NIRCMD:

http://www.nirsoft.net/utils/nircmd.html

though NOT the answer to all questions (as an example the Answer to the ultimate question about life, the universe and everything is instead 42 ;)) it does represent an answer to most common day problems where bathc is involved.

exec hide, exec2 hide or execmd might be what you need:

http://www.nirsoft.net/utils/nircmd2.html#using

Or use any of the various alternative approaches:

http://blogs.technet.com/b/heyscriptingguy/archive/2007/12/05/hey-scripting-guy-how-can-i-start-a-script-in-a-hidden-window.aspx

http://superuser.com/questions/62525/run-a-completly-hidden-batch-file

Apart for the "pure .vbs" ones, the Iexpress one could be handy.

Thanks again you been an amazing help.

No prob :).

jaclaz

0

Share this post


Link to post
Share on other sites

You do not need any 3rd party application to run a vbs script without showing any Cmd Window.

Show Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Hide Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 0, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, True

Another Example Hidden Window that produces a text file with no Window Showing


CreateObject("Wscript.Shell").Run(_
"%Comspec% /C @Echo Off && CLS && Echo Test Line 1 > Test.txt && " & _
"Ping -n 2 127.0.0.1>nul && Echo Test Line 2 >> Test.txt"),0,True

0

Share this post


Link to post
Share on other sites

You do not need any 3rd party application to run a vbs script without showing any Cmd Window.

Show Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 1, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 1, True

Hide Window


Option Explicit
Dim objShell
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("%comspec% /K assoc.java=java.Document "), 0, True
objShell.Run("%comspec% /K ftype java.Document =""C:\Program Files (x86)\Ready to Program\Ready.exe"" ""%1"""), 0, True

Another Example Hidden Window that produces a text file with no Window Showing


CreateObject("Wscript.Shell").Run(_
"%Comspec% /C @Echo Off && CLS && Echo Test Line 1 > Test.txt && " & _
"Ping -n 2 127.0.0.1>nul && Echo Test Line 2 >> Test.txt"),0,True

Thanks man.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.