how to get Music Duration using asp on W2K12 server - vbscript

this question is a follow-on from Read music file length in VBScript but as I am new I don't seem to be able to add comments or ask questions on that post :(.
So, I have copied the code as posted by #Helen as per below and it works perfectly on my Win10 laptop, however when I try the same on my W2K12 R2 server, the results are sadly very different. I still get some properties, such as you might expect from a normal file, but the duration is blank. I have modified it to pull all properties (ie length = 0 to 1000 in a loop) and some properties are populated but nothing looking like duration... :(
Const LENGTH = 27 ' Windows Vista+
' Const LENGTH = 21 ' Windows XP
Dim oShell : Set oShell = CreateObject("Shell.Application")
Dim oFolder : Set oFolder = oShell.Namespace("C:\Music")
Dim oFile : Set oFile = oFolder.ParseName("Track.mp3")
Dim strLength : strLength = oFolder.GetDetailsOf(oFile, LENGTH)
WScript.Echo strLength
Does anyone understand why this won't work on my W2K12 server?
I have tried changing the folder attributes from "general" to "optimised for music" but still no luck..

Be sure file permission is correct.
And you can try run vbs like this: Run > cmd > "%windir%\SysWOW64\cscript.exe" C:\test.vbs

Related

vbscript does not execute as desired

i've been googling the last couple of days for a solution to my problem.
There seems to be a ton of questions asked on this topic but somehow they are not working for me or (most likely) i'll be doing something wrong.
Const OverwriteExisting = True
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim FSO, MyFile, FileName, strFileName, strCopyTo
Set FSO = CreateObject("Scripting.FileSystemObject")
strFileName = "C:\......SourceFolder\SourceFile.html"
strCopyTo = "T:\....DestinationFolder\"
FileName = "T:\........\autorun.inf"
If FSO.FileExists(strFileName) Then
FileSystemObject.CopyFile strFileName, strCopyTo, True
'FSO.CopyFile strFileName, strCopyTo, OverwriteExisting
Else
For i = 1 to 3
If FSO.FileExists(strFileName) Then
FileSystemObject.CopyFile strFileName, strCopyTo, True
else
WScript.sleep 1000 '1000 milliseconds
End if
Set MyFile = FSO.OpenTextFile(FileName, ForAppending, True, TristateTrue)
' Write to the file.
MyFile.WriteLine "Attempt " & i & " - " & Now
MyFile.Close
Next
End If
What i'm trying to do is copying a file from the source folder located on C:\ to a shared network drive called T:.
So i started the script with checking if the file exist, if it exists than it will have to copy it to the destination folder.
If not i would like to try 3 more times with each at least 1 second a part from each other. for that i'm using the FOR method and WScript.sleep function. And if it didn't exist i'm writing it to a file.
Everything is working fine, except for the most important thing, the file even though it does exist it does not get copied.
I've checked the attributes on the origin and destination file, as according to google, the read-only attribute would prevent the file from being copied even when in the copy function "overwrite" is set to TRUE.
So i do not know where to look right now and would greatly appreciate any help.
Thanks
Philippe
I'm going to go ahead and post this as an answer instead of a comment, because I'm pretty sure it's what's causing your problem.
In the lines where you're trying to do the copying, you have
FileSystemObject.CopyFile [...]
However, at no point do you define a variable, let alone an object, named FileSystemObject. Your file system object is actually defined as
Set FSO = CreateObject("Scripting.FileSystemObject")
That's FSO, not FileSystemObject. Try changing your CopyFile lines to:
FSO.CopyFile strFileName, strCopyTo, True
If you started your code with <%Option Explicit%>, the interpreter ("compiler") would catch these sorts of errors for you.

VBS - Weird Japanese characters conversion

I've been searching Google and StackOverflow and did find some partial answers to my problem. Here is my question:
I've bee n trying to make a small script that will promt the user for keywords and once you hit enter it will parse the array into Chrome or Firefox and open up tabs with all the various searches. It works! But, then I wanted to expand on that so I could make a .txt file and make it read from that, that works too! BUT since it's a Japanese site we're searching, Japanese will yield better results!
So I got the ForReading and TriState/Unicode = -1 to work, and it does issue something in Japanese, the problem is it doesn't issue the characters I inserted into the document. :/ And I'm at a loss at the moment. Here's the part of the code that I need some help with:
'Declaring
Option Explicit
Const ForReading = 1
Const Unicode = -1
Dim FullPath
Dim objShell
Dim SearchArray
Dim Figure
Dim Index
Dim listWord
Dim Mandarake
Dim invalidName
Dim rawImport
Dim objFSO
Dim objTextFile
FullPath = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FullPath&"\mandalist.txt", ForReading,True,Unicode)
Set objShell = CreateObject("Shell.Application")
SearchArray = Array()
mandarake = "http://ekizo.mandarake.co.jp/shop/en"
'Starting do loop until we trigger the search with "go"
Do
ReDim Preserve SearchArray(UBound(SearchArray)+1)
Figure = InputBox("Enter a name or type 'go' when you're done!", "Figure search", "List")
SearchArray(UBound(SearchArray)) = "http://ekizo.mandarake.co.jp/shop/en/search.do?action=keyword&doujin=all&keyword="&Replace(Figure," ","+")
'Trying to handle empty or "Name" entry into array error
If Figure = Empty Then
invalidName = MsgBox("Are you sure you want to quit?",1,"Are you sure?")
If invalidName = vbOK Then
WScript.Quit (0)
End If
ElseIf Figure = "List" Then
Do Until objTextFile.AtEndOfStream
rawImport = objTextFile.Readline
Figure = Replace(rawImport," ","+")
SearchArray = Split(Figure , ",")
Call objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", mandarake, "", "", 1)
For Index = 0 To UBound(SearchArray)
Call objShell.ShellExecute("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe", "http://ekizo.mandarake.co.jp/shop/en/search.do?action=keyword&doujin=all&keyword="&SearchArray(index), "", "", 1)
WScript.Sleep(1500)
Next
WScript.Quit (0)
Loop
I have more code hence all the dims and set's, but that is if the If Figure = "List" is not true and it will then continue to the insertion of manual keywords, and those works even with Japanese signs. The thing is, no matter what I paste into the text file it will parse other characters (also some Japanese stuff) into the URL instead of what I put in. How can I get it to treat the charset as it's supposed to?
Example would be:
Text in Mandalist.txt = グリフォン アスナ
Text in URL in Chrome = 믯낂菣閃苣뎃ꊂ苣誃 - HMF :s
Any help would be much appreciated.
PS - This is my first project where I don't rely on a piece of paper that my teacher wrote me in school, so it may be simple but I just can't make it work.
Thanks
/CuraeL

vb script not working on windows 8

I have a script that I'm using to add watermarks to pdf and worked fine with windows vista and xp
With windows script I'm getting this error :
80070005
This is the script I'm using :
Option Explicit
Const Watermark = "watermark.pdf"
Const Watermark2 = "AAAWatermark.pdf"
Dim objArgs, fname, tfname, fso, pdf
Set objArgs = WScript.Arguments
fname = objArgs(0)
Set fso = CreateObject("Scripting.FileSystemObject")
tfname = fso.GetTempName
Set pdf = WScript.CreateObject("pdfforge.pdf.pdf")
pdf.StampPDFFileWithPDFFile fname, tfname, Watermark, 1, 9999, false, 1, 10
If fso.FileExists(tfname) Then
fso.DeleteFile(fname)
fso.MoveFile tfname, fname
Else
MsgBox "There was an error adding the Watermark!", vbCritical, AppTitle
End If
Set pdf = Nothing
Set fso = Nothing
Set objArgs = Nothing
Any ideal please?
Thank you
Although I'm a little rough with my Francais, it would appear that you do not have rights to save temporary files in that directory mentioned in the error box or the directory does not exist? You could right click the folder and go to le security tab and add the everyone object and assign write access (or something more secure if you have some other group, etc)
(Edit: The original post had a screenshot in French for added context here)

get the target path from a nethood link

Let's say I have a nethood link to a folder with the name "BLABLA" and the target path is "\\servername\temp"
how do I get the string for the target path?
I tried:
Set oShell = CreateObject("WScript.Shell")
Const NET_HOOD = &H13&
Set oShApp = CreateObject("Shell.Application")
sNetHood = oShApp.NameSpace(NET_HOOD).Self.Path
Set oShortCut = oShell.CreateShortcut(sNetHood & "\" & "BLABLA" & ".lnk")
MsgBox "> " & oShortCut.TargetPath
It does everything, even creates a oShortCut object without any errors.
But, it does not return
oShortCut.TargetPath
what am I doing wrong?
I'd like it to return this: "\\servername\temp\BLABLA"
Thanks in advance for any advice!
I've created the shortcut under win 7 with right click in Computer view of the explorer and then > Add a network location > Next ... etc. It creates a Folder representing a shortcut in NetHood to the path on the server ... it's like a mapped share but not really it.
thx for the input ... after years of reading myself into the matter and then checking google once more i found a c# code which i wrote into vbs and then simplified only to see that all i had to change in the end was to add this:
.GetLink
so the solution to my problem is:
Const NET_HOOD = &H13&
Set oShell = CreateObject("Shell.Application")
Set oFolder = oShell.NameSpace(NET_HOOD)
For Each oFile In oFolder.Items
MsgBox oFile.GetLink.Path
Next

VBS Runtime error code 800A01B6

I am a newbie to VBS scripting. I am getting above error on line 54, character 5 in script below. This error says "Object doesn't support this property or method: 'MimeMapArray'".
And line it is referring to is:
MimeMapArray(i) = CreateObject("MimeMap")
Can u tell me what I am doing wrong? Here is the script in its entirety. Note, I am trying to run this on an XP OS by double-clicking this VBS file.
' This script adds the necessary Windows Presentation Foundation MIME types
' to an IIS Server.
' To use this script, just double-click or execute it from a command line.
' Running this script multiple times results in multiple entries in the IIS MimeMap.
' Set the MIME types to be added
Dim MimeMapObj
Dim MimeMapArray
Dim WshShell
Dim oExec
Const ADS_PROPERTY_UPDATE = 2
Dim MimeTypesToAddArray
MimeTypesToAddArray = Array(".manifest", "application/manifest", ".xaml", _
"application/xaml+xml", ".application", "application/x-ms-application", _
".deploy", "application/octet-stream", ".xbap", "application/x-ms-xbap", _
".xps", "application/vnd.ms-xpsdocument")
' Get the mimemap object
Set MimeMapObj = GetObject("IIS://LocalHost/MimeMap")
' Call AddMimeType for every pair of extension/MIME type
For counter = 0 to UBound(MimeTypesToAddArray) Step 2
AddMimeType MimeTypesToAddArray(counter), MimeTypesToAddArray(counter+1)
Next
' Create a Shell object
Set WshShell = CreateObject("WScript.Shell")
' Stop and Start the IIS Service
Set oExec = WshShell.Exec("net stop w3svc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Set oExec = WshShell.Exec("net start w3svc")
Do While oExec.Status = 0
WScript.Sleep 100
Loop
Set oExec = Nothing
' Report status to user
WScript.Echo "Windows Presentation Foundation MIME types have been registered."
' AddMimeType Sub
Sub AddMimeType(ByVal Ext, ByVal MType)
' Get the mappings from the MimeMap property.
MimeMapArray = MimeMapObj.GetEx("MimeMap")
' Add a new mapping.
i = UBound(MimeMapArray) + 1
ReDim Preserve MimeMapArray(i)
MimeMapArray(i) = CreateObject("MimeMap")
MimeMapArray(i).Extension = Ext
MimeMapArray(i).MimeType = MType
MimeMapObj.PutEx ADS_PROPERTY_UPDATE, "MimeMap", MimeMapArray
MimeMapObj.SetInfo()
End Sub
The first thing I can suggest is use cscript to execute. You can get more information that won't go away like with a message box.
Open a command prompt (go to start,
run, type CMD).
Go to the location where your script
is and type the following:
cscript scriptname.vbs
...where scriptname.vbs is the name of your script.
Second, you appear to be missing the "set" in front of your createobject line. Have a look here for reference.
That line should look like:
set MimeMapArray(i) = CreateObject("MimeMap")

Resources