Ever have to open a file in VBS and its all messed up. The file may be in UTF8 or Unicode.
The is especially annoying for SQL files so I did this:
'**************************************************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\UnknownFile.SQL")
'Set this to false so it opens as ascii
Set objTextStream = objFile.OpenAsTextStream(1,False)
'Grab the first line
strTemp = objTextStream.ReadLine
If InStr(strTemp,"") > 0 Then
'UTF8 = depends on the content
'I stripped out the wacky characters and was OK
MsgBox("File is UTF8")
ElseIf InStr(strTemp,"ÿþ/") > 0 Then
'Unicode = just open the file again with
'Set objTextStream = objFile.OpenAsTextStream(1,True)
MsgBox("File is Unicode")
Else
'File is normal
MsgBox("File is ANSI")
End If
'**************************************************
Showing posts with label vbs. Show all posts
Showing posts with label vbs. Show all posts
Tuesday, May 5, 2009
Friday, May 1, 2009
Set A Vdir property from VBS
Couldn't find a decent sample online for this functions so heres mine:
Set providerObj = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
'Change Report Server to the VDIR your trying to manage
Set IIsWebVirtualDirObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/Root/ReportServer'")
'Set some properties here, notice the _
'Where the hell did that come from? Dunno but it works
' List of properties are here http://msdn.microsoft.com/en-us/library/ms525644.aspx
IIsWebVirtualDirObj.Properties_("AuthFlags").Value =1
IIsWebVirtualDirObj.Properties_("AnonymousUserName").Value= "Domain\User"
IIsWebVirtualDirObj.Properties_("AnonymousUserPass").Value = "Password"
'Put it!!!!!! Set it....
IIsWebVirtualDirObj.Put_()
Set providerObj = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
'Change Report Server to the VDIR your trying to manage
Set IIsWebVirtualDirObj = providerObj.get("IIsWebVirtualDirSetting='W3SVC/1/Root/ReportServer'")
'Set some properties here, notice the _
'Where the hell did that come from? Dunno but it works
' List of properties are here http://msdn.microsoft.com/en-us/library/ms525644.aspx
IIsWebVirtualDirObj.Properties_("AuthFlags").Value =1
IIsWebVirtualDirObj.Properties_("AnonymousUserName").Value= "Domain\User"
IIsWebVirtualDirObj.Properties_("AnonymousUserPass").Value = "Password"
'Put it!!!!!! Set it....
IIsWebVirtualDirObj.Put_()
Subscribe to:
Posts (Atom)