www.webdeveloper.com
Page 1 of 7 123 ... LastLast
Results 1 to 15 of 103

Thread: Creating windows startup script

  1. #1
    Join Date
    Dec 2010
    Posts
    77

    Creating windows startup script

    Hi all,

    I need to create windows startup script that opens default web browser and navigate to some site say google.com

    i've tried to use the following script:
    window.open("http://google.com");

    but the following error occured:
    Line:1
    Char:1
    Error: 'window' is undefined
    Code: 800A1391
    Source: Microsoft JScript runtime error

    could anybody please help me on this

    thanks in advance
    Last edited by devmostafa; 12-13-2010 at 05:09 AM.

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    You could do it with a batch file...

    Startup.bat
    Code:
    @Echo Off
    Cls
    Start IExplore "http://www.google.com/"
    Or with VBScript...

    Startup.vbs
    Code:
    Dim Shell
    
    	Set Shell = WScript.CreateObject("WScript.Shell")
    	Call Shell.Run("http://www.google.com/", 1)
    	Set Shell = Nothing
    Last edited by thraddash; 12-13-2010 at 05:22 AM. Reason: Added VBScript version

  3. #3
    Join Date
    Dec 2010
    Posts
    77
    Dear thraddash,

    is there anyway to do it using javascript ??
    if not

    then please help me with more details about using this batch file

    and what if i need to open the browser according to an if else condition based on a value that is retrieved from a database

    thanks in advance

  4. #4
    Join Date
    Aug 2009
    Posts
    593
    I wouldn't personally make a logon script with Javascript, you should really be using VBScript for that purpose. (as above)

    It is possible to open a database connection in VBScript as well, although I don't have a working example on me at this time.

    Can you explain your scenario further?

  5. #5
    Join Date
    Dec 2010
    Posts
    77
    Dear thraddash,

    here is the scenario:
    1 - i have a DB
    2 - i need to retrieve a numeric value from it
    3 - if this value is less than 40 then the browser is opened and will navigate to a specific website

    if you could help me i will appreciate this

    thanks in advance

  6. #6
    Join Date
    Dec 2010
    Posts
    77
    Dear thraddash,

    is there a way to connect to db using batch file ???

  7. #7
    Join Date
    Aug 2009
    Posts
    593
    I have made the assumption that you are using mySQL, and the mySQL 5.1 ODBC driver is required for it to work. You can get it from here (http://www.mysql.com/downloads/connector/odbc/)

    This is used in a VBScript...

    Query.vbs
    Code:
    Dim Connection
    Dim Recordset
    Dim SQL
    
    	SQL = "SELECT * FROM [table]"
    
    	Set Connection = WScript.CreateObject("ADODB.Connection")
    	Set Recordset  = WScript.CreateObject("ADODB.Recordset")
    	Call Connection.Open("Driver={MySQL ODBC 5.1 Driver}; Server=localhost; Database=[database]; User=[username]; Password=[password]; Option=3")
    	Call Recordset.Open(SQL, Connection)
    
    	Do While NOT Recordset.EOF   
    		Call MsgBox(Recordset("id"))
    		Call Recordset.MoveNext()
    	Loop
    
    	Call Recordset.Close()
    	Call Connection.Close()
    	Set Recordset  = Nothing
    	Set Connection = Nothing
    You will need to modify the connection string with your database, username and password. Also there is a MsgBox where I alert the table column value, you must change it or add additional lines for more column values.

    I have tested this on my own mySQL database and it returned the correct results.

    Hope this helps.
    Last edited by thraddash; 12-13-2010 at 08:18 AM.

  8. #8
    Join Date
    Dec 2010
    Posts
    77
    Dear thraddash,

    would you please help me with the equivalent javascript code ??

    or a tool to convert it

    thanks in advance

  9. #9
    Join Date
    Aug 2009
    Posts
    593
    The JavaScript version. You will still need the mySQL 5.1 ODBC driver (http://www.mysql.com/downloads/connector/odbc/).

    Query.js
    Code:
    var
    	Statement  = 'SELECT * FROM [table]',
    	Connection = new ActiveXObject('ADODB.Connection'),
    	Recordset  = new ActiveXObject('ADODB.Recordset'),
    	Shell      = new ActiveXObject('WScript.Shell');
    
    Connection.Open('Driver={MySQL ODBC 5.1 Driver}; Server=localhost; Database=[database]; User=[username]; Password=[password]; Option=3');
    Recordset.Open(Statement, Connection);
    
    while (!Recordset.EOF) {   
    	Shell.Popup(Recordset('[field]'), 0, 'Message', 48);
    	Recordset.MoveNext();
    }
    
    Recordset.Close();
    Connection.Close();
    Again, change the connection string with your database, username and password.

  10. #10
    Join Date
    Dec 2010
    Posts
    77
    Dear Thraddash,

    if i'm using MS SQL server DB how could i get the driver, and how should i change the follwoing ??
    Driver={MySQL ODBC 5.1 Driver};

    thanks in advance

  11. #11
    Join Date
    Dec 2010
    Posts
    77
    Dear Thraddash,

    I've tried to run this query

    var Statement = "SELECT coalesce(TotalWork,0) AS TotalWork FROM dual as x left outer join (SELECT 1 as Y,CONVERT(INT, SUM(MSP_TimesheetActual.ActualWorkBillable)) AS TotalWork FROM MSP_EpmResource LEFT OUTER JOIN MSP_TimesheetResource INNER JOIN MSP_TimesheetActual ON MSP_TimesheetResource.ResourceNameUID = MSP_TimesheetActual.LastChangedResourceNameUID ON MSP_EpmResource.ResourceUID = MSP_TimesheetResource.ResourceUID LEFT OUTER JOIN MSP_TimesheetPeriod INNER JOIN MSP_Timesheet ON MSP_TimesheetPeriod.PeriodUID = MSP_Timesheet.PeriodUID ON MSP_TimesheetResource.ResourceNameUID = MSP_Timesheet.OwnerResourceNameUID WHERE (MSP_EpmResource.ResourceNTAccount = 'INTERCOM\%username%') AND (MSP_TimesheetActual.TimeByDay BETWEEN MSP_TimesheetPeriod.StartDate AND MSP_TimesheetPeriod.EndDate) GROUP BY MSP_TimesheetPeriod.StartDate, MSP_TimesheetPeriod.EndDate HAVING (MSP_TimesheetPeriod.StartDate <= DATEADD(d, - 7, GETDATE())) AND (MSP_TimesheetPeriod.EndDate >= DATEADD(d, - 7, GETDATE()))) as y on x.x=y.Y";
    var Connection = new ActiveXObject('ADODB.Connection');
    var Recordset = new ActiveXObject('ADODB.Recordset');
    var Shell = new ActiveXObject('WScript.Shell');

    Connection.Open('Data Source={servername};Initial Catalog={database name};User ID={username};Password={password};Provider=SQLOLEDB');
    Recordset.Open(Statement, Connection);
    Recordset.MoveFirst();

    while (!Recordset.EOF)
    {
    Shell.Popup(Recordset('TotalWork'), 0, 'Message', 48);
    Recordset.MoveNext();
    }

    Recordset.Close();
    Connection.Close();


    but for some reasons it returns 0
    and while i'm trying to run it on sql server it returns the correct value
    have you any idea about where the error may be ??

  12. #12
    Join Date
    Aug 2009
    Posts
    593
    Im taking a wild guess here, but the part in your statement where your matching the username...

    Code:
    (MSP_EpmResource.ResourceNTAccount = 'INTERCOM\&#37;username%')
    Does MS Sql translate the variable into the user currently logged on, if so I have the suspition that it isnt working from a remote computer.

    Try running this statement on the remote computer and on the server to see what the differences are...

    Code:
    SELECT '%username%'
    If this happens to be the issue, then I can help you get that value from the windows environment variables.

  13. #13
    Join Date
    Dec 2010
    Posts
    77
    Dear thraddash,

    good guessing this statement should retrieve the current user

    i've tried to run this script:
    var Statement = "select ResourceNTAccount from MSP_EpmResource";
    var Connection = new ActiveXObject('ADODB.Connection');
    var Recordset = new ActiveXObject('ADODB.Recordset');
    var Shell = new ActiveXObject('WScript.Shell');

    Connection.Open('Data Source=projectserver;Initial Catalog= PWA_ProjectServer_Reporting;User ID=sa;Password=intercom.com.eg;Provider=SQLOLEDB');

    Recordset.Open(Statement, Connection);
    Recordset.MoveFirst();

    while (!Recordset.EOF)
    {
    Shell.Popup(Recordset('ResourceNTAccount'));
    Recordset.MoveNext();
    }

    Recordset.Close();
    Connection.Close();

    and it works perfectly both in the server and the remote computer even in the client computer

    but when i change the query to something like:
    select ResourceNTAccount from MSP_EpmResource where ResourceNTAccount='someuser'

    the following error ocurred:

    Line:10
    Char:1
    Error: Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.
    Code: 800A0BCD
    Source: ADODB.Recordset

    i'm sure that the user exist and i've tried to run the query on the sql server and it runs successfully

    have you any suggestions ??

    thanks alot for your help

  14. #14
    Join Date
    Aug 2009
    Posts
    593
    Try something like this....

    Code:
    var Connection  = new ActiveXObject('ADODB.Connection');
    var Recordset   = new ActiveXObject('ADODB.Recordset');
    var Shell       = new ActiveXObject('WScript.Shell');
    var Environment = Shell.Environment("Process");
    var Statement   = 'SELECT ResourceNTAccount FROM MSP_EpmResource WHERE ResourceNTAccount LIKE "&#37;' + Environment('UserName') + '"';
    
    	Shell.Popup(Statement, 0, 'Statement', 0);
    
    	Connection.Open('Data Source=projectserver;Initial Catalog= PWA_ProjectServer_Reporting;User ID=sa;Password=intercom.com.eg;Provider=SQLOLEDB');
    	Recordset.Open(Statement, Connection);
    	//Recordset.MoveFirst();
    
    	while (!Recordset.EOF) { 
    		Shell.Popup(Recordset('ResourceNTAccount'));
    		Recordset.MoveNext();
    	}
    
    	Recordset.Close();
    	Connection.Close();
    I think your MoveFirst request is causing problems, especially if there were no records found. Also, I have changed the query to request the current user of the remote computer. You can also pull their current domain but lets see if this does anything first.

    The statement that will be sent to the MS SQL server will be alerted so you can check if its correct.
    Last edited by thraddash; 12-21-2010 at 05:05 AM.

  15. #15
    Join Date
    Dec 2010
    Posts
    77
    dear thraddash,

    Line: 10
    Char: 2
    Error: An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Add a name or single space as the alias name.
    Code: 80040E14
    Source: Microsoft OLE DB Provider for SQL Server

    any suggestions ??

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles