Jump to content

Welcome to MSFN Forum
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.
Login to Account Create an Account



Photo

Need help to change the default program for .java files

- - - - -

  • Please log in to reply
12 replies to this topic

#1
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
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/ho...171_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



How to remove advertisement from MSFN

#2
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,562 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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

#3
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05

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...tions-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.

#4
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,562 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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...s-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.blo...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.n...es_manager.html

jaclaz

#5
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05


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...s-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.blo...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.n...es_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, 16 September 2012 - 10:51 AM.


#6
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,562 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag
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

#7
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
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, 16 September 2012 - 03:18 PM.


#8
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05
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.

#9
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,562 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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

#10
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05


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.

#11
jaclaz

jaclaz

    The Finder

  • Developer
  • 14,562 posts
  • Joined 23-July 04
  • OS:none specified
  • Country: Country Flag

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.n...ils/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.n...cmd2.html#using

Or use any of the various alternative approaches:
http://blogs.technet...den-window.aspx
http://superuser.com...dden-batch-file
Apart for the "pure .vbs" ones, the Iexpress one could be handy.

Thanks again you been an amazing help.

No prob :).

jaclaz

#12
gunsmokingman

gunsmokingman

    MSFN Master

  • Super Moderator
  • 2,419 posts
  • Joined 02-August 03
  • OS:none specified
  • Country: Country Flag
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 



GunSmokingMan



#13
clivebuckwheat

clivebuckwheat

    Senior Member

  • Member
  • PipPipPipPip
  • 577 posts
  • Joined 07-November 05

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users