Quantcast
Channel: VBForums - ASP, VB Script
Viewing all 702 articles
Browse latest View live

[RESOLVED]Check running program, start if not running VBscript.

$
0
0
Hello!

First of all, im totaly new to this and i dont know if im posting this in the right forum. Admin can delete/move this post if it's in the wrong place.

I have a Windows 2000 server (Yes i know it's lighyears old but i ) where i run 2 small programs that collects data from different places.
One of those programs chrashes 2-3 times a month and therefore i was looking after a script that could check if the program is running and run it if it isnt. :)
Easy as pie, so I thought.
Googled alot after different script, all that i found and tried got me different error messages and didnt work in Win 2000, most of them worked on my Win10 PC.
Then I foudn this VBscript that didn't produce any error instead nothing happened. so i thought maybe this could work if it just got modified a bit?
And that is why I need your help here guys, is it possible to manage this in Win2000 ?

Script:

Dim objWMIService, colItems, objItem, strComputer, strFlashEXEFile
Dim count

strFlashEXEFileName = "BarkStat.exe"
strFlashEXEFilePath = "C:\BarkStat\BarkStat" & strFlashEXEFileName
strComputer = "."

Set objWMIService = GetObject("winmgmts:" & strComputer & "\root\cimv2")
Set colItems = objWMIService.InstancesOf("Win32_Process")

count = 0

For Each objItem In colItems
If objItem.Name = strFlashEXEFileName Then
count = count + 1
Else
End If
Next

Set objWMIService = Nothing
Set colItems = Nothing

If count = 0 Then

Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
Return = oShell.run(strFlashEXEFilePath,3, false)
Set oShell = Nothing

End If

[RESOLVED] vbs to download data from url as csv table

$
0
0
Hi!

I am using the following code to download data from a website using vbs. The data is held in the webpage in table form. However, the resulting downloaded data is in the form of a simple continuous text, which I cannot import into excel and use as a table. (I can download the same using excel etc., but I find vbs to be much faster and efficient).

The solution at https://www.example-code.com/vbscrip...ble_to_csv.asp allows converting the downloaded data to csv format, but requires specific api and software to be pre-installed.

I was wondering if it would be possible to download the data in csv format using vbs only and without using a third-party software.

Also, I had posted this request on Stackoverflow at https://stackoverflow.com/questions/...91746#65891746. A user had posted a probable solution, but I am unable to use it due to my limited vbs literacy.

Perhaps above links could give some ideas?

Code:

For i = 1 to 1
createFile(i)
Next

Public Sub createFile(a)

    Dim fso,MyFile
    filePath = "D:\file_name" & a & ".txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = fso.CreateTextFile(filePath)


myURL = "https://www.investing.com/indices/major-indices"

'Create XMLHTTP Object & HTML File
Set oXMLHttp = CreateObject("MSXML2.XMLHTTP")
Set ohtmlFile = CreateObject("htmlfile")

'Send Request To Web Server
oXMLHttp.Open "GET", myURL, False
oXMLHttp.send

'If Return Status is Success
If oXMLHttp.Status = 200 Then

    'Get Web Data to HTML file Object
    ohtmlFile.Write oXMLHttp.responseText
    ohtmlFile.Close
       
    'Parse HTML File
    Set oTable = ohtmlFile.getElementsByTagName("table")
    For Each oTab In oTable
        MyFile.WriteLine oTab.Innertext
    Next
        MyFile.close
End If

End Sub

'Process Completed
'WScript.Quit

Note:

1. I would request to kindly post the full working code with modifications to download the data in csv format, since I am not familiar with vbs.

2. The file with the above code needs to be saved in D:\ as any_name.vbs and resulting downloaded data file will be downloaded in D:\

Thanks.

Vb Function

$
0
0
Hello Guys.,:wave:

Hope all r doing great.

I have a requirement of getting multiple return values from a vb function as Array format or just like multiple variables.

Is there any possibility for that..??

Regards
Sudheer:)

Microsoft Edge in Kiosk Mode - Please help

$
0
0
This is my first ever vb.script and I'm having trouble making Microsoft Edge open in Kiosk mode could someone please help me modify the line of code.
Here is my code
set shell = CreateObject("WScript.Shell") : Do : shell.run "microsoft-edge:http://www.google.com/", 3, True : Loop

If someone could help me that would be great

Thanks
David

VBscript save PDF-file

$
0
0
Hello,

I'm looking for some kind of script that automatically saves a PDF-file when printing.

Example:
I open a PDF-file in my browser. I print this file and then automatically the script saves the PDF-file somewhere.

Is this possible?

Thanks in advance,

Schiavoni

WinHttpRequest - errors like 'method cannot be called until open/send has been called

$
0
0
Hi,

After both Opening and Sending a request, some of the propertes of a WinHttpRequest are displaying errors.


Code:

On Error Resume Next

    Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
    Request_s = "GET"
    
    objHTTP.Open Request_s, Url_s, False
    objHTTP.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
    objHTTP.SetCredentials User_s, Password_s, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
    objHTTP.Send Credentials_s
  '// BELOW, Status (and ResponseBody and ResponseText, etc.) are showing that the request hasn't been sent, even though it just was.
  '// ALSO, the Option property says that the Open method must be called.
    Status_n = objHTTP.Status
    Status_Text_s = objHTTP.StatusText
    HTML_s = objHTTP.ResponseText

Pass all arguments into array VBS

$
0
0
0


I want to run jsx script and passing argument into array

Code:

Const psNeverShowDebugger = 1, psDebuggerOnError = 2, psBeforeRunning = 3

Dim appRef
Set appRef = CreateObject("Photoshop.Application")

Dim infosDoc
infosDoc = Wscript.arguments()

Dim JSXFile
JSXFile = Wscript.arguments(0)

appRef.DoJavaScriptFile "C:\Program Files\Adobe\Adobe Photoshop 2020\Presets\Scripts\"+JSXFile+".jsx", Array(infosDoc), psNeverShowDebugger

Im getting the first argument in JSXFile but not getting all arguments in infosDoc so im a bit confuse, if someone can help me!

Thanks you!

Creating pdf from gridview with selected rows.

$
0
0
Hello guys,

I need help for my webpage.

I made a SQL database which include my data and I created 2 pages that I and my customer can look data in Gridview.

One of my client asked me that she wants to select data and download as list from gridview in excel or pdf.

I succeeded to make it one of page which is main page that I can add new data from that page.

But when I tried same code to add in customer page there has error that I can not find solution.

Name:  Capture.jpg
Views: 6
Size:  17.8 KB

Here is some part from my customer.aspx included gridview part.
Code:

<script type="text/javascript">
        var gridViewId = '#<%= GridView1.ClientID %>';
        function checkAll(selectAllCheckbox) {
            //get all checkbox and select it
            $('td :checkbox', gridViewId).prop("checked", selectAllCheckbox.checked);
        }
        function unCheckSelectAll(selectCheckbox) {
            //if any item is unchecked, uncheck header checkbox as also
            if (!selectCheckbox.checked)
                $('th :checkbox', gridViewId).prop("checked", cbSelectAll.checked = "");
        }
    </script>

<asp:panel ID="panel2" runat="server" style="width:76%; float:right; margin-bottom:0px; margin-top:1px">
        <div style ="background-color:lightgray; border-color:black; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px; 
        height:40px;width:100%; margin:0;padding:0">
        <table cellspacing="0" cellpadding = "0" rules="all" id="tblHeader" style="font-family:Arial;font-size:10pt;color:black; border:none;
        border-collapse:collapse;height:100%;width:100%;float:left; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">
            <tr>
              <td style="width:17px; border:none"></td>
                <td style="width:20px; border:none"><asp:CheckBox ID="cbSelectAll" runat="server" onclick="checkAll(this);" ></asp:CheckBox></td>
              <td style ="width:63px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Rapor Tarihi</td>
              <td style ="width:64px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Rapor Numarası</td>
              <td style ="width:93px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Kurum Adı</td>
              <td style ="width:90px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Markası</td>
              <td style ="width:75px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Modeli</td>
              <td style ="width:92px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Seri Numarası</td>
              <td style ="width:64px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Servis Mühendisi</td>
              <td style ="width:50px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Servis Nedeni</td>
              <td style ="width:50px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Cihazın Durumu</td>
              <td style ="width:112px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Açıklama</td>
              <td style ="width:128px;text-align:center; font-family:Helvetica; text-align:left; font-size:11px; border:none; border-bottom-left-radius:20px; border-bottom-right-radius:20px; border-top-left-radius:20px; border-top-right-radius:20px">Yapılan İşlemler</td>
              <td style="width:50px; border:none"></td>
            </tr>
        </table>
        </div>
        <div class="mostly-customized-scrollbar" style="height:470px; border:none; width:96.8%; margin:0;padding:0;">
            <asp:GridView ID="GridView1" runat="server" Width="100%" BorderStyle="Solid" borderwidth="1px" BorderColor="black" AlternatingRowStyle-BorderColor="black" AlternatingRowStyle-BorderStyle="Solid" AlternatingRowStyle-BorderWidth="1px" HorizontalAlign="Left" AutoGenerateColumns = "False" Font-Names = "Helvetica"  ShowHeader = "False"
            Font-Size = "12px" OnRowDataBound="OnRowDataBound" Height="40px" charset="CP1254" CurrentSortField="Rapor Numarası" CurrentSortDirection="DESC">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:CheckBox ID="cbSelect" runat="server" onclick="unCheckSelectAll(this);" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Rapor Tarihi" HeaderText="Rapor Tarihi" SortExpression="Rapor Tarihi" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass"  BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Rapor Numarası" HeaderText="Rapor Numarası" SortExpression="Rapor Numarası" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Kurum Adı" HeaderText="Kurum Adı" SortExpression="Kurum Adı" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Cihazın Markası" HeaderText="Cihazın Markası" SortExpression="Cihazın Markası" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Cihazın Modeli" HeaderText="Cihazın Modeli" SortExpression="Cihazın Modeli" ItemStyle-Width="8%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="8%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Seri Numarası" HeaderText="Seri Numarası" SortExpression="Seri Numarası" ItemStyle-Width="10%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="10%"/>
                    </asp:BoundField>
                    <asp:BoundField DataField="Servis Mühendisi" HeaderText="Servis Mühendisi" SortExpression="Servis Mühendisi" ItemStyle-Width="7%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="7%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Servis Nedeni" HeaderText="Servis Nedeni" SortExpression="Servis Nedeni" ItemStyle-Width="5%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="5%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Cihazın Durumu" HeaderText="Cihazın Durumu" SortExpression="Cihazın Durumu" ItemStyle-Width="5%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="5%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Açıklama" HeaderText="Açıklama" SortExpression="Açıklama" ItemStyle-Width="13%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="13%" />
                    </asp:BoundField>
                    <asp:BoundField DataField="Yapılan İşlemler" HeaderText="Yapılan İşlemler" SortExpression="Yapılan İşlemler" ItemStyle-Width="13%" ItemStyle-Height="40px" ItemStyle-BorderStyle="None" >
                        <ItemStyle CssClass="itemclass" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" Height="40px" Width="13%" />
                    </asp:BoundField>
                    <asp:CommandField ShowSelectButton="True" ItemStyle-Width="4%" ItemStyle-ForeColor="#191970" SelectText="Seç" ItemStyle-BorderStyle="None">
                        <ItemStyle ForeColor="MidnightBlue" Width="4%" BorderStyle="Solid" BorderWidth="1px" BorderColor="black" />
                    </asp:CommandField>
                </Columns>
            </asp:GridView>
        </div>
    </asp:panel>

And here is my pdf codes.
Code:

    Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
    End Sub

    Protected Sub ImageButton4_Click(sender As Object, e As ImageClickEventArgs) Handles ImageButton4.Click
        Dim Helvetica = iTextSharp.text.pdf.BaseFont.CreateFont("Helvetica", "CP1254", iTextSharp.text.pdf.BaseFont.NOT_EMBEDDED)
        Dim t1 = New iTextSharp.text.Font(Helvetica, 24, FontStyle.Bold)
        Dim t2 = New iTextSharp.text.Font(Helvetica, 10, FontStyle.Regular)
        Dim t3 = New iTextSharp.text.Font(Helvetica, 12, FontStyle.Bold)
        Using a1 As StringWriter = New StringWriter()
            Using a2 As HtmlTextWriter = New HtmlTextWriter(a1)
                GridView1.Columns(0).Visible = False
                GridView1.Columns(12).Visible = False
                For Each r1 As GridViewRow In GridView1.Rows
                    If r1.RowType = DataControlRowType.DataRow Then
                        r1.Visible = (TryCast(r1.FindControl("cbSelect"), CheckBox)).Checked
                    End If
                Next
                GridView1.RenderControl(a2)
                Dim a3 As StringReader = New StringReader(a1.ToString())
                Dim cusdoc As Document = New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
                cusdoc.SetPageSize(iTextSharp.text.PageSize.A4.Rotate())
                Dim w1 As PdfWriter = PdfWriter.GetInstance(cusdoc, Response.OutputStream)
                cusdoc.Open()
                Dim logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/images/farmakim logo.png"))
                logo.SpacingAfter = 0
                logo.ScaleAbsolute(20, 140)
                Dim Empty As New PdfPTable(3)
                Empty.SetWidths(New Integer() {350, 700, 350})
                Empty.DefaultCell.BorderColor = BaseColor.WHITE
                Empty.WidthPercentage = 100.0F
                Empty.SpacingBefore = 100
                Empty.DefaultCell.VerticalAlignment = VerticalAlign.Middle
                Empty.HorizontalAlignment = HorizontalAlign.Center
                Empty.DefaultCell.FixedHeight = 40
                Empty.AddCell(logo)
                Empty.AddCell(New Phrase("Servis Raporları Özeti", t1))
                Empty.AddCell(New Phrase("www.farmakim.com.tr", t3))
                cusdoc.Add(Empty)
                Dim table1 As New PdfPTable(11)
                table1.SetWidths(New Integer() {69, 69, 96, 96, 78, 87, 78, 50, 50, 124, 124})
                table1.WidthPercentage = 100.0F
                table1.DefaultCell.BorderColor = BaseColor.BLACK
                table1.DefaultCell.BorderWidth = 1.5
                table1.DefaultCell.VerticalAlignment = VerticalAlign.Middle
                table1.HorizontalAlignment = 0
                table1.DefaultCell.FixedHeight = 26
                table1.AddCell(New Phrase("Rapor Tarihi", t2))
                table1.AddCell(New Phrase("Rapor Numarası", t2))
                table1.AddCell(New Phrase("Kurum Adı", t2))
                table1.AddCell(New Phrase("Cihazın Markası", t2))
                table1.AddCell(New Phrase("Cihazın Modeli", t2))
                table1.AddCell(New Phrase("Seri Numarası", t2))
                table1.AddCell(New Phrase("Servis Mühendisi", t2))
                table1.AddCell(New Phrase("Servis Nedeni", t2))
                table1.AddCell(New Phrase("Cihazın Durumu", t2))
                table1.AddCell(New Phrase("Açıklama", t2))
                table1.AddCell(New Phrase("Yapılan İşlemler", t2))
                table1.AddCell(New Phrase("", t2))
                cusdoc.Add(table1)
                iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(w1, cusdoc, a3)
                cusdoc.Close()
                Response.ContentType = "application/pdf"
                Response.AddHeader("content-disposition", "attachment;filename=Farmakim - " + Now + ".pdf")
                Response.Cache.SetCacheability(HttpCacheability.NoCache)
                Response.Write(cusdoc)
                Response.[End]()
            End Using
        End Using
    End Sub

Is there anyone that who can help me.
Attached Images
 

Detecting and avoiding duplicate data stored in a loaded CSV

$
0
0
Morning VB community..

I am involved with a project where they have provided me a CSV file with a 3-column comma delimited data array..

It goes as follows:

Machine Name, UserID, LabelID
MSI-MACHINE01,adm-testaccoun!,LABELNAME1

This CSV file has over a thousand rows with Machine Names associated with the same LabelID at least once as follows:

Code:

MSI-MACHINE01,adm-testaccoun!,LABELNAME1
MSI-MACHINE01,adm-testaccount,LABELNAME2
MSI-MACHINE02,adm-testaccoun!,LABELNAME3
MSI-MACHINE03,adm-testaccount,LABELNAME4

Essentally, we use the CSV to capture what MachineIDs or UserIDs are attached to that third column "LabelID" and write this to a txt file called "ShortcutFile" to the user's own Z:\UserDesktop\.

So the scenario is as follows:

If the below script reads the CSV file with the MachineID or UserID matches the LabelID data on the third column then write a ShortcutFile 1.txt to Z:\UserDesktop\ in an area of the txt called "LABELNAME001" which replaces it with the LabelID found.

Before doing this it checks for the existence of any older named .txt of this type and renames them to .old as a quick backup process.

This all works fine when the MachineID or UserIDs have different LabelIDs as follows in the loaded CSV:

Code:

MSI-MACHINE01,adm-testaccoun!,LABELNAME1
MSI-MACHINE0!,adm-testaccount,LABELNAME2
MSI-MACHINE01,adm-testaccoun!,LABELNAME3
MSI-MACHINE0!,adm-testaccount,LABELNAME4

So the above scenario if the machine I am on is called "MSI-MACHINE01" and the user ID I am using is "adm-testaccount" it will create the following Shortcut X.txt files in Z:\UserDesktop\

Shortcut 1.txt -> saves as "LABELNAME1" within the txt file
Shortcut 2.txt -> saves as "LABELNAME2" within the txt file
Shortcut 3.txt -> saves as "LABELNAME3" within the txt file
Shortcut 4.txt -> saves as "LABELNAME4" within the txt file

Problem is: when it finds this instead in the CSV:

Code:

MSI-MACHINE01,adm-testaccoun!,LABELNAME1
MSI-MACHINE0!,adm-testaccount,LABELNAME1
MSI-MACHINE01,adm-testaccoun!,LABELNAME2
MSI-MACHINE0!,adm-testaccount,LABELNAME2

It will create these shortcut files:

Shortcut 1.txt -> saves as "LABELNAME1" within the txt file
Shortcut 2.txt -> saves as "LABELNAME1" within the txt file
Shortcut 3.txt -> saves as "LABELNAME2" within the txt file
Shortcut 4.txt -> saves as "LABELNAME2" within the txt file

The objective we want is if it detects trying to save the same kind of LabelID it will skip it to go onto the next unique label so the above scenario we want is this:

Shortcut 1.txt -> saves as "LABELNAME1" within the txt file
Shortcut 2.txt -> saves as "LABELNAME2" within the txt file

So as you see we want it to skip writing Shortcut 2.txt with "LABELNAME1" (since it wrote it already in Shortcut 1.txt) and move onto the next unique LabelID and write it as the next incremented Shortcut X.txt.

Here is the code we are using..

Code:

On Error Resume Next

Const ForReading = 1
Const ForWriting = 2
Const CSV_File = "WorkstationUserLabel.csv"
Const LABEL_Filename = "ShortcutFile"
Const LABEL_TargetPath = "Z:\UserDesktop\"
Dim CurDir, oFSO, sCSV, fCSV, aCSV_Line, sComputerName, sUserName, nFileIndex, fLABEL, sLABELContents

netDrive = "Z:\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
baseDir = "UserDesktop"
If Not objFSO.FolderExists (netDrive & baseDir) Then
    objFSO.CreateFolder(netDrive & baseDir)
Else

End If

'Search Z:\UserDesktop and rename existing ShortcutFile-only LABEL files to OLD
Set strUserDesktop = objFSO.GetFolder("Z:\UserDesktop")
Set folder = objFSO.GetFolder(strUserDesktop)

For each file In folder.Files 
    If instr(file, "ShortcutFile") > 0 OR instr(file, "shortcutfile") > 0 THEN
        file.name = replace(file.name, ".txt", ".old")
    End IF
 Next

sComputerName = CreateObject("WScript.Network").ComputerName
sUserName = CreateObject("WScript.Network").UserName

Set oFSO = CreateObject("Scripting.FileSystemObject")
CurDir = oFSO.GetParentFolderName(WScript.ScriptFullName)
If Right(CurDir, 1) <> "\" Then CurDir = CurDir & "\"

sCSV = CurDir & CSV_File

If oFSO.FileExists(sCSV) Then
    Set fCSV = oFSO.OpenTextFile(sCSV, ForReading)
        Do Until fCSV.AtEndOfStream
            aCSV_Line = Split(fCSV.ReadLine, ",")
            If ((aCSV_Line(0) = sComputerName) Or (aCSV_Line(1) = sUserName)) Then  'Scan .CSV file for relevant Computer and Users and associate them to a LABEL NAME
                nFileIndex = 1
                Do Until Not(oFSO.FileExists(LABEL_TargetPath & LABEL_Filename & Chr(32) & cStr(nFileIndex) & ".txt"))
                    nFileIndex = nFileIndex + 1
                Loop
                oFSO.CopyFile CurDir & LABEL_Filename & ".txt", LABEL_TargetPath & LABEL_Filename & Chr(32) & cStr(nFileIndex) & ".txt" 'If associated LABEL file is detected, copy the select one(s) to Z:\UserDesktop
                Set fLABEL = oFSO.OpenTextFile(LABEL_TargetPath & LABEL_Filename & Chr(32) & cStr(nFileIndex) & ".txt", ForReading)
                    sLABELContents = fLABEL.ReadAll
                fLABEL.Close
                sLABELContents = Replace(sLABELContents, "LABELNAME001", aCSV_Line(2))
                Set fLABEL = oFSO.OpenTextFile(LABEL_TargetPath & LABEL_Filename & Chr(32) & cStr(nFileIndex) & ".txt", ForWriting) 'Associate detected LABEL NAME to declared LABEL filenames using how many Computer or Users are either found
                    fLABEL.WriteLine sLABELContents
                fLABEL.Close
            End If
        Loop
    fCSV.Close
End If

All help is most appreciated.

Searching Active Directory Sub OU's with script

$
0
0
I have an old vbs script that I'd like to reuse versus rewrite. It works, but it's not able to search sub OU's using LDAP search.
It does use a csv as a validation script file, and that part works fine.
I have a feeling this is an easy fix to make it search resursively. Any assistance would be much appreciated.
Without giving too much private information away:

Code:

Sub DumpLDAPUserInfo
Dim MyiOUcnt
Dim MyioUsercnt
Dim MyarrCols
Dim MysKey
Dim MysEmail
' Insert code securely
    sLDAPServer = "test.com"
    sUser = "testuser"
    sPassword = "Password1"
    sCN = "/CN=" & sUser
    sDN = "CN=" & sUser & "OU=Users,OU=Corporation,DC=Test,DC=com"
    sOUDNQuery = "LDAP://test.com/OU=Users,OU=Corporation,DC=Test,DC=com"

    Set oDS = GetObject("LDAP:")
    Set oOUDN = oDS.OpenDSObject( _
                sOUDNQuery, _
                sUser, _
                sPassword, _
                ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
    sMsg = oOUDN.Class & vbCrLf & sOUDNQuery & vbCrLf & _
          "Click OK to Continue ..."
    Call DisplayMsg(sMsg,5,vbInformation)
    MyiOUcnt = 0
    MyioUsercnt = 0
    sLastCN = ""
    For each oOU in oOUDN
        MyiOUcnt = MyiOUcnt + 1
        MysKey = oOU.cn
        If dictValidation.Exists(MysKey) Then
          MyarrCols = Split(dictValidation(MysKey),"|")
          sEmplID = MysKey
          sFirstName = MyarrCols(10)
          sLastName = MyarrCols(11)
          sEmail = MyarrCols(9)
          MysEmail = oOU.mail
          If (oOU.mail <> "") AND (lcase(oOU.mail) <> lcase(sEmail)) Then
'              If MyioUsercnt < 10 Then
'                sMsg = oOU.cn & vbCrLf & _
'                  oOU.displayName  & vbCrLf & _
'                  oOU.givenName  & vbCrLf & _
'                  oOU.sn & vbCrLf & _
'                  oOU.mail & vbCrLf & _
'                  "Old email: " & sEmail
'                Call DisplayMsg(sMsg,2,vbInformation)
'              End If
              Call WriteOutput
              MyioUsercnt = MyioUsercnt + 1
          End If
          sLastCN = oOU.cn
        End If
    Next
    sMsg = "oOU count=" & CStr(MyiOUcnt) & vbCrLf & _
          "oUser count=" & Cstr(MyioUsercnt) & vbCrLf & _
          "Output count=" & Cstr(iOutcnt)
End Sub

Help needed to automate console input

$
0
0
Hello,

Below is my command to perform one activity. It accepts few arguments which is fine and no issues there. But when we run that command in cmd, it asks for password and confirm password.
I want to automate that password and confirm password part. How can I do that?

Example:

When we run below command in cmd -

c:\Test\myscript.exe --arg1 --arg2 --config "c:\Temp\config.cfg" --confirm

It shows below in same command prompt-

Performing the script execution for ABCD.

Enter password:

Type again to confirm:


What I need is, How can I automate this entering of password and confirm password, considering I have the password.
Please help here. PowerShell or VBScript is preferred solution.

Input a password to dialog box after launching app through VB script

$
0
0
I have written a script that launches an application from my desktop. I have no knowledge in scripting, but was able to google around and have it done. However I am stuck at a point where I am not able to input the password in the dialog box that gets opened when I launch the app. Below is code :

Dim exeName
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

exeName = """Actual Application path"""

call WshShell.Run (exeName, 1, true)
WScript.Sleep(100)
WshShell.AppActivate "TAE" '-- Please note that TAE is the name that appears on title bar of the app
WScript.Sleep(100)

'Passing the value password
WSHShell.SendKeys "welcome124"

'MOving to enter
WSHShell.SendKeys "{TAB}"

'Clicking enter to complete the screen
WSHShell.SendKeys "{ENTER}"
set WshShell=Nothing

Application gets launched and I get a dialog box which already has the username and cursor is on the password text field. Nothing happens after that. Sometimes password gets entered in some other application that is open - like notepad

Arguments_are_of_the_wrong_type_are_out_of_acceptable_range_or_are_in_conflict_with_o

$
0
0
I am getting Arguments_are_of_the_wrong_type_are_out_of_acceptable_range_or_are_in_conflict_with_one_another

on rstUpload.Open strSQL, Application("gstrDbConnProp"), 1,3


and I have no idea why


Set rstUpload = Server.CreateObject("adodb.recordset")
rstUpload.Open strSQL, Application("gstrDbConnProp"), 1,3


It looks perfectly ok to me. Ha sanyone got any pdeas whyc please?

Thanks

Want to take SAP application screenshots with Full screen

$
0
0
I am unable to take SAP application screenshots (full screen with Time Stamp) while SAP Scripting using vb script.

Please help me soon.

Automate export of Excel file to XML file

$
0
0
Hi all,
I have about 200 xlsx files that are exportable to XML.
So I want to automate the process of export (not conversion but export).

Here is a pseudo code :

Code:

For each xlsx file
begin
        open file with Excel
        go to developper tab
        export to XML
        set xmlFilename
        save xmlFilename
end

How can I do that ?

Thanks in advance

Help Having Script Export To EXCEL\TSV File Instead of TXT File

$
0
0
Hi,

I have hacked together the below code to grab information from WMIC and currently have it export to a TXT document.
The aim of the script is for users to run it and it will automatically capture their details and their pc\monitor's details.

I am hoping someone can assist in making my code:

1) Write the data to an Excel\TSV file instead of TXT file into specified columns with headers.
e.g. Column A = NAME column - the code from below for Name would paste the data into A2 and so on.

2) A check so that if someone runs the script more than once on the second running they will get a message advising that their information has already been collected (I have seen this once before by checking the name \ pc serial against information in the Excel\TSV but cannot locate this code to use\edit for my purpose).

Thanks in advance for any and all help!

t0ny84

Code:

Function BytesToString(ByVal Bytes)
  Dim Result, N
  Result = ""
  For N = 0 To UBound(Bytes)
    If CInt(Bytes(N)) <> 0 Then
      Result = Result & Chr(Bytes(N))
    Else
      Exit For
    End If
  Next
  BytesToString = Result
End Function

Dim fso
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
CurrentDirectory = fso.GetAbsolutePathName(".")

Set f = fso.createTextFile(currentdirectory & "\" & "output.txt", 2)

strComputer = "."

' WMI NameSpaces
Set objWMIServiceWMI =  GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set objWMIServiceCIMV2 = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")

Set MonItems = objWMIServiceWMI.ExecQuery("SELECT * FROM WmiMonitorID")
Set PCItems = objWMIServiceCIMV2.ExecQuery("SELECT * FROM Win32_BIOS")
Set colItems = objWMIServiceCIMV2.ExecQuery("SELECT * FROM Win32_ComputerSystem")

Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)

If Not monItems Is Nothing Then
For Each objMon in monItems
        If monSerial <> "" Then
        monSerial = monSerial & ", "
        End If
        monSerial = monSerial & BytesToString(objMon.SerialNumberID)
        Next

For Each objMon in monItems
        If monUFN <> "" Then
        monUFN = monUFN & ", "
        End If
        monUFN = monUFN & BytesToString(objMon.UserFriendlyName)
        Next
End If

For each objItem in ColItems
    f.WriteLine "-----------------------------------"
    f.WriteLine "User Information:"
    f.WriteLine "-----------------------------------"
    f.WriteLine "ID: " & objUser.CN
    f.WriteLine "Full Name: " & objUser.FullName

    f.WriteLine " "

    f.WriteLine "-----------------------------------"
    f.WriteLine "PC Information:"
    f.WriteLine "-----------------------------------"
    f.WriteLine "Domain\User ID: " & objItem.UserName
    f.WriteLine "PC Manufacturer: " & objItem.Manufacturer
    f.WriteLine "PC Model: " & objItem.Model
    f.WriteLine "Serial: " & objItem.Name
Next

For Each objItem in PCItems
    f.WriteLine "PC Serial Number: " & objItem.SerialNumber
Next

For Each objItem in MonItems
    f.WriteLine "-----------------------------------"
    f.WriteLine "Monitor Data"
    f.WriteLine "-----------------------------------"
    If isNull(objItem.UserFriendlyName) Then
        f.WriteLine "UserFriendlyName: "
    Else
        f.WriteLine "UserFriendlyName: " & BytesToString(objItem.UserFriendlyName) & vbNewLine & "Serial:" &  BytesToString(objitem.SerialNumberID) & vbNewLine & "ManufacturerName: " & bytestostring(objItem.ManufacturerName) & vbNewLine & "YearOfManufacture: " & objItem.YearOfManufacture
End If
Next
Wscript.echo "End"

f.Close

How does VBS call ACTIVEX DLL generated by VB.NET

$
0
0
How does VBS call ACTIVEX DLL generated by VB.NET? How to deal with data type conversion?
like sum(a,b),sum(33,44)=77
vbs:
Code:

dim obj,v
obj=createobject(**)
v=obj.sum(33,44)
msgbox v'it's ok
msgbox "ss" & v'it's err

Can the address of a VB Function be used to execute the function in some way?

$
0
0
Hi,

Outside of an Events context, can the address of a function obtained with GetRef(), be used in a variable which will later be used to execute the function?

What I'm trying to accomplish is sending the function name as parameter on the command line, and then executing that function inside the script, something like:

WScript test.vbs "FirstFunction"


Code:

'**** Test.vbs
Option Explicit

Function ExecuteFunction( FunctionName )
Dim RetVal

RetVal = RunThis( &Function )

ExecuteFunction = RetVal
End Function

' **** All defined functions ****


Function FirstFunction
...
End Function

Function SecondFunction
...
End Function

'*** End of test.vbs ***

What does BTT mean?

$
0
0
Hi,

When creating an object from a third party library, CreateObject returns a popup


VBScript RunTime Error
This operation is not supported with BTT enabled.


What does 'BTT enabled' mean?

Error 91 VBscript parsing html text to excel

$
0
0
I tried to simulate a VB Script from this forum: Search a website with Excel data to extract results and then loop

I got an error on this line:

URL_Get_ABN_Query = entityRange.Offset(0, 1).Value2
the error is: error 91 object variable or with block variable not set

Here is the two-part script of the said forum:

Code:

Sub LoopThroughBusinesses()
    Dim i As Integer
    Dim ABN As String
    For i = 2 To Sheet1.UsedRange.Rows.Count
        ABN = Sheet1.Cells(i, 2)
        Sheet1.Cells(i, 3) = URL_Get_ABN_Query(ABN)
    Next i
End Sub

Function URL_Get_ABN_Query(strSearch As String) As String  ' Change it from a Sub to a Function that returns the desired string
' strSearch = Range("a1") ' This is now passed as a parameter into the Function
Dim entityRange As Range
With Sheet2.QueryTables.Add( _
        Connection:="URL;http://www.abr.business.gov.au/SearchByABN.aspx?SearchText=" & strSearch & "&safe=active", _
        Destination:=Sheet2.Range("A1"))  ' Change this destination to Sheet2

    .BackgroundQuery = True
    .TablesOnlyFromHTML = True
    .Refresh BackgroundQuery:=False
    .SaveData = True
End With

' Find the Range that has "Finish"
Set entityRange = Sheet2.UsedRange.Find("Entity type:")

' Then return the value of the cell to its' right
URL_Get_ABN_Query = entityRange.Offset(0, 1).Value2

' Clear Sheet2 for the next run
Sheet2.UsedRange.Delete

End Function

Viewing all 702 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>