vb script not working on windows 8 - vbscript

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)

Related

how to get Music Duration using asp on W2K12 server

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

How to create exe file using VBS

How to make executable file with VBS. There is a code for txt but how to change it to make from this exe
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const Append = 8
Dim FDir
FDir = ("Area where file will be saved")
Const FName_Ext = "Title of document.txt"
Dim Final
Final = FDir + FName_Ext
Dim objtxt
set objtxt = objFSO.CreateTextFile(Final, True)
Set objtxt = Nothing
Dim FWrite
Set FWrite = objFSO.OpenTextFile(Final, Append)
FWrite.WriteLine("this is the text in the file.!!! hahaha lol wohoo yada yada yada. okay done!")
FWrite.Close()
Set FWrite = Nothing
Set objFSO = Nothing
Get familiar with PE Headers . Short, this is a lot of binary data that tells windows where to find what when it starts to execute your file. Although vbs was not designed for binary magic, the simple text way does the trick if you have saved your binary data into a variable, at least according to this microsoft doc.

filesize returns zero when read from remote server using VBscript

I am trying to read a file size from remote server using ftp credentials in Vb script,i have the following code below which returns remote file size zero.Anythink which i done wrong?.Please help me,Your solution could be appreciated here
Dim fso, folder1, folder2, folder2a
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder2a = fso.GetFolder("C\samples\")
ftpFolderString = "ftp://xxx:yyyy#www.hostname.com/Folder"
targetFoldder = "C\samples"
Dim SH, txtFolderToOpen, thing
Set SH = CreateObject("Shell.Application")
Set folder1 = SH.NameSpace(ftpFolderString)
Set folder2 = SH.NameSpace(targetFoldder)
For Each item In folder1.items
MsgBox item.size
For Each item2 In folder2a.Files
If item2.size< item.Name Then
..do stuff
End IF
Next
Next
I am getting remote file size zero.Could you pl help me what i went wrong in that script
While the docs don't say anything, it's common that some object properties aren't available on remote items. Try using the fso object size property. It is a completely different mechanism.
From Help
Function ShowFolderSize(filespec)
Dim fso, f, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(filespec)
s = UCase(f.Name) & " uses " & f.size & " bytes."
ShowFolderSize = s
End Function
Line 3 a typo?
"C\samples\"
Should be
"C:\samples\"

Copy unformatted plain text to the clipboard using VBScript

I'm using the following function in my VBScript to copy a string onto the clipboard without the use of the external clip command (which isn't and cannot be installed due to security policies):
Function CopyToClipboard(sText)
Dim oWord : Set oWord = CreateObject("Word.Application")
With oWord
.Visible = False
.Documents.Add
.Selection.TypeText sText
.Selection.WholeStory
.Selection.Copy
.Quit False
End With
Set oWord = Nothing
End Function
The problem is that the string being copied comes with the standard formatting inherited by the "normal.dot" template.
Given that I have Word 2003, this formatting is Times New Roman, 12pt and in black. So when it gets pasted into an email or document, the formatting doesn't match with the existing content.
Is there any way to remove the formatting on the string in the clipboard?
After playing around a bit, I developed a solution that doesn't use the Word object model, but does copy unformatted text to the clipboard - which is what I needed to do:
Function CopyToClipboard(sText)
' Create temporary text file to avoid IE clipboard warnings
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Dim sTemp : sTemp = fso.GetSpecialFolder(2) & "\" & fso.GetTempName
Dim oFile : Set oFile = fso.CreateTextFile(sTemp, True)
oFile.Write "This file can be safely deleted"
oFile.Close
Set oFile = Nothing
' Start Internet Explorer in the local zone
Dim oIE : Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = 0
oIE.Navigate2 sTemp
Do
WScript.Sleep 100
Loop Until oIE.Document.ReadyState = "complete"
' Copy contents to clipboard
oIE.Document.ParentWindow.ClipboardData.SetData "text", sText
' Clean up
fso.DeleteFile sTemp
Set oIE = Nothing
Set fso = Nothing
End Function
This code uses Internet Explorer's ability to access the clipboard in order to paste in the contents of sText. You'll notice that about:blank isn't used as the starting page and this is because it will generate the following warning:
In order to get around this we create a temporary file locally (with some copy to indicate that it is benign) and then navigate to this file. As a result Internet Explorer treats this page in the "Local Intranet" zone and allows access to the clipboard without generating a pop-up confirmation.

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

Resources