How can I run the vbscript as the 'Administrator' but access on APPDATA folder of current logon user VBSCRIPT
Date : March 29 2020, 07:55 AM
I hope this helps you . Cannot do this with a VBS alone. You would need to create a batch file to pass this %APPDATA% environment variable into the script as Argument, then modify the VBS script to process this argument(s). Dim sTxt
sTxt = WScript.Arguments.Count & " arguments passed into vbs:"
sTxt = sTxt & JoinArgs
wscript.echo sTxt
Function JoinArgs()
Dim sTmp
sTmp = ""
For Each oArg In Wscript.Arguments
sTmp = sTmp & vbCrLf & oArg
Next
JoinArgs = sTmp
End Function
@echo off
C:\SysInt\psexec.exe -u %computername%\administrator -p AccountPassword -e wscript.exe "c:\debug\vbs\test.vbs" %appdata%
|
Looking for a VBScript to move files older than 3 years to a new folder while keeping the folder structure
Date : March 29 2020, 07:55 AM
should help you out I am looking to move files from my file server to a tape drive to save space. I need a script that will allow me to move all the files that were accessed 3 years ago or later while still keeping their folder structure. Dim objFSO, ofolder, objStream, strSafeDate, strSafeTime, strDateTime, strLogFileName
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
strSafeDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date), 2) & Right("0" & DatePart("d",Date), 2)
strSafeTime = Right("0" & Hour(Now), 2) & Right("0" & Minute(Now), 2) & Right("0" & Second(Now), 2)
Set strDateTime equal to a string representation of the current date and time, for use as part of a valid Windows filename
strDateTime = strSafeDate & "-" & strSafeTime
'Assemble the path and filename
strLogFileName ="Move File " & strDateTime & ".txt"
set outfile = fso.createtextfile(strLogFileName,true)
SPath = "I:\Tech Docs\"
Sdest = "I:\Test\"
ShowSubfolders FSO.GetFolder(spath)
Sub ShowSubFolders(Folder)
CheckFolder Folder
For Each Subfolder in Folder.SubFolders
ShowSubFolders Subfolder
Next
End Sub
'CheckFolder(objFSO.getFolder(SPath))
Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile
Const OverwriteExisting = TRUE
currDate = Date
dtmDate = DateAdd("d",-0,Now)
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
'Since we want to preserve the path, we've got to reconstruct it
sAbsPath = objFile.Path
'Swap source and destination in the path, and strip the file name
'from the path.
sNewPath = Replace(Replace(sAbsPath,sPath,Sdest),"\" & objFile.Name,"")
'Here we reconstruct the path if it doesn't exist in the
'destination with our new Sub "MakeDir"
MakeDir sNewPath
FileName = objFile
'WScript.Echo FileName
'strDate = ConvDate(objFile.DateCreated)
strDate = ConvDate(objFile.DateLastAccessed)
If strDate =< strTargetDate Then
'Finally we copy the file to the sNewPath
objFSO.MoveFile FileName, sNewPath & "\"
outfile.writeline Filename
End If
Next
End Sub
Sub MakeDir(strPath)
On Error Resume Next
strParentPath = objFSO.GetParentFolderName(strPath)
If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder strPath
On Error Goto 0
End Sub
Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function
|
VBScript - Find files in folder by string in filename, move found to different folder
Date : March 29 2020, 07:55 AM
will be helpful for those in need Here you go, I fixed your if/then statements and added and if fso.fileexists: dim fso, folder, newfolder, sourcefolder, destfolder, searchname1, searchname2, searchname3
sourcefolder = "C:\Users\...\Desktop"
destfolder = "C:\Users\...\Desktop\Sorted\"
searchname1 = "youtube"
searchname2 = "bbc"
searchname3 = "facebook"
set fso = createobject("scripting.filesystemobject")
set folder = fso.getfolder(sourcefolder)
if not fso.folderexists(destfolder) then
newfolder = fso.createfolder(destfolder)
wscript.echo "'Sorted' folder created in path: " & vbcrlf & sourcefolder
end if
for each file in folder.files
x = fso.getbasename(file)
if instr(lcase(x), searchname1) > 0 or instr(lcase(x), searchname2) > 0 or instr(lcase(x), searchname3) > 0 then
if fso.fileexists(destfolder & "\" & file.name) then
fso.deletefile destfolder & "\" & file.name, true
fso.movefile sourcefolder & "\" & file.name, destfolder
else
fso.movefile sourcefolder & "\" & file.name, destfolder
end if
end if
next
wscript.echo "Files moved to 'Sorted' in path: " & vbcrlf & sourcefolder
|
itextsharp - convert page to PDF and auto save to a temp folder without opening a download dialog
Tag : chash , By : SilverRuby
Date : March 29 2020, 07:55 AM
like below fixes the issue So you want to save it on the server? Do you want to display the pdf to the browser without prompting the user to save? Perhaps the answer from this previous post on SO can help. I recall that the behavior might vary depending on the browser (IE, Chrome, Firefox, Safari). When using: Response.AddHeader("Content-Disposition", "inline;filename=somefile.ext")
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=RequestSummaryReport.pdf");
|
Run convert from VBScript on all files in a folder
Date : March 29 2020, 07:55 AM
should help you out Here, I took a stab at it. Seems you've got a lot of excessive work for nothing. A lot of strings combining empty strings and characters... See below. Test it out making any syntax adjustments and you're all set. The shell command execution will run as this in the current formatting.... cmd.exe /c "C:\Users\Kamil\Desktop\Nowyfolder\PDF TO TIFF imagemagick\tify\convert.exe -type bilevel -compress Group4 -pointsize 20 -draw "text 10,20 \'PropertyValue1 PropertyValue2 PropertyVAlue3 PropertyValue4 PropertyValue5\'" somefile.tif"
strfldr = "C:\Users\Kamil\Desktop\Nowyfolder\PDF TO TIFF imagemagick\tify"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colFolder = objFSO.GetFolder(strfldr)
Set colFiles = colFolder.Files
'unnecessary array removed
For Each objfile In colFiles 'Properly notate file as Object, not string
'if instr(1, objFile.Name, ".tif", 1) <> 0 Then ShellRun(ConvertFile(objFile.Name))
if instr(1, objFile.Name, ".tif", 1) <> 0 Then ShellExec(ConvertFile(objFile.Name))
Next
Function ConvertFile(strFileName)
Exec = "C:\Users\Kamil\Desktop\Nowyfolder\PDF TO TIFF imagemagick\tify\convert.exe"
TypeParam = "-type bilevel"
CompParam = "-compress Group4"
PsizeParam = "-pointsize 20"
DrawParam = "-draw ""text 10,20 \'PropertyValue1 PropertyValue2 PropertyVAlue3 PropertyValue4 PropertyValue5\'"""
Params = TypeParam & " " & CompParam & " " & PsizeParam & " " & DrawParam & " " & strFileName & " " & strFileName
ConvertFile = """" & Exec & " " & Params & """"
'Returns properly formatted Command string
End Function
Function ShellRun(strCommand)
On Error Resume Next
if NOT isObject(shell) then Set shell = CreateObject("Wscript.Shell")
wscript.echo strcommand
shell.run "cmd.exe /c " & strCommand, 0, true
If Err.Number <> 0 Then
msgbox "Error Code:" & err.Number & vbCrLf & "Error Description: " & Err.Description, 0, "Shell Command Error " & err.number & "!"
err.clear
End if
on error goto 0
Set shell = nothing
'Executes command shell hidden - returns error code via msgbox.
End Function
Sub ShellExec(strCommand)
ShellExecReturn = CreateObject("Wscript.Shell").Exec("cmd /c " & strCommand ).stdout.readall
wscript.sleep 1000
wscript.echo ShellExecReturn
End Sub
|