Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Create a file association

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2099
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create a file association
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Create a file association - 2/18/2005 1:03:36 AM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Hi all

I am learning VB as Kix is my chosen scripting language but are new infrastrucutre is using VB login scripts for all are XPsp2 clients.

I need to create a file association and have found the following code

'Declarations:


'(None)
'Code:


Public Sub associate(EXT As String, FileType As String, _
FileName As String)
On Error Resume Next
Dim b As Object
Set b = CreateObject("wscript.shell")
b.regwrite "HKCR\" & EXT & "\", FileType
b.regwrite "HKCR\" & FileType & "\", "MY file"
b.regwrite "HKCR\" & FileType & "\DefaultIcon\", FileName
b.regwrite "HKCR\" & FileType & "\shell\open\command\", _
FileName & " %L"
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\FileExts\" & EXT & "\Application"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\FileExts\" & EXT & "\Application", FileName
b.regdelete "HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\FileExts\" & EXT & "\OpenWithList\"
b.regwrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer\FileExts\" & EXT & "\OpenWithList\a", FileName

End Sub

'Sample Usage
Private Sub Form_Load()
associate ".jpg", "JPGFile", _
"C:\Program Files\Accessories\MSPAINT.EXE"
Unload Me
End Sub


But it is coming up with an error about 'Expected ('

? Im confused as to why this isnt working, can anyone help?

Thanks

Aaron
 
 
Post #: 1
 
 Re: Create a file association - 2/18/2005 3:57:15 AM   
  drbelden

 

Posts: 109
Score: 0
Joined: 12/21/2004
From: USA
Status: offline
Does it tell you what line the error is on?

This looks more like VB than VBS.

(in reply to AzzerShaw)
 
 
Post #: 2
 
 Re: Create a file association - 2/18/2005 2:12:02 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I never understand why people are reluctant to mention exactly which LINE in a script produced an error. So here it is again, what LINE is the error on ?

I believe it's VB, VBS doesn't allow you to decalre variable types.

(in reply to AzzerShaw)
 
 
Post #: 3
 
 Re: Create a file association - 2/18/2005 3:11:31 PM   
  tnoonan

 

Posts: 364
Score: 0
Joined: 12/14/2004
From:
Status: offline
agree tick out on error so it will report line. Use primalscript or some other third party. Helps us alot if you post code and line error so we do not waste alot of time, since most of us are responding to you between calls and projects at work or on our own time, which is suppose to be relaxing, which I Know for a fact token and several others have given there free time weekend and such helping others.

(in reply to AzzerShaw)
 
 
Post #: 4
 
 Re: Create a file association - 2/20/2005 7:59:05 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Line 5
Char 26
Error Expected ')'

(in reply to AzzerShaw)
 
 
Post #: 5
 
 Re: Create a file association - 2/20/2005 8:25:28 PM   
  Zifter


Posts: 318
Score: 0
Joined: 1/5/2005
From: Belgium
Status: offline
Like the others already mentioned, in vbscript you can't declare the variable type.
Just remove all the "as ..." and it works like a charm.


      HTH

(in reply to AzzerShaw)
 
 
Post #: 6
 
 Re: Create a file association - 2/20/2005 9:52:53 PM   
  AzzerShaw

 

Posts: 25
Score: 0
Joined: 10/22/2004
From:
Status: offline
Thanks very much for all your help works like a gem

Aaron

(in reply to AzzerShaw)
 
 
Post #: 7
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Create a file association Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts