Skip to content

Logging on to a Server

You can use the Logon method (function) from your program or script to log on to a z/OS server. An example of when you would use Logon is when your program or script is accessing a data set on a z/OS server.

The following scripts illustrate how to log on to a z/OS server.

C# Example

...

/**********************************************************************
* C# Example
* 
* File Name: Logon.cs
*
* Description: Logon to server. If userid and password not specified,
* user will be prompted.
*
* Usage: Logon <server> [<userid>] [<password>] [<newpassword>]
*
* Copyright ©2007, Serena Software. Licensed material. All rights reserved.
**********************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using ZosApi;

namespace Logon
{
class Program
{
    static void Main(string[] args)
    {
        try
        {
            //////////////////////////////
            // Get command line arguments
            //////////////////////////////

            if (args.Length < 1)
            {
                Console.WriteLine("Usage: Logon <server> [<userid>]
                 [<password>] [<newpassword>]");
                Environment.Exit(0);
            }

...

...

            String serverName;
            String userID;
            String password;
            String newPassword;

            serverName = args[0];

            if (args.Length > 1)
            {
                userID = args[1];
            }
            else
            {
                userID = "";
            }
            if (args.Length > 2)
            {
                password = args[2];
            }
            else
            {
                password = "";
            }

            if (args.Length > 3)
            {
                newPassword = args[3];
            }
            else
            {
                newPassword = "";
            }

            ///////////////////
            // Logon to server
            ///////////////////
            ZosNetwork network = new ZosNetwork();
            ZosServer server = network.Servers[serverName];

            if (server == null)
            {
                Console.WriteLine("Server {0} not found", serverName);
                Environment.Exit(1);
            }
            server.Logon(userID, password, newPassword);

            Console.WriteLine("User {0} logged onto {1}", userID, serverName);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.TargetSite);
            }
        }
    }
}

Visual Basic Example

...

'**********************************************************************
' Visual Basic Example
' File Name: Logon.vb
'
' Description: Logon to server. If userid and password not specified,
' user will be prompted.
'
' Usage: Logon <server> [<userid>] [<password>] [<newpassword>]
'
' Copyright ©2007, Serena Software. Licensed material. All rights reserved.
'**********************************************************************

...

...

Imports System   
Imports ZosApi
Module Logon

    Sub Main()

    Try

        '----------------------------
        ' Get command line arguments
        '----------------------------

        Dim args As String() = Environment.GetCommandLineArgs()

        If args.Length < 2

            Console.WriteLine("Usage: Logon <server> (<userid>) (<password>) _
        (<newpassword>)")
        Environment.Exit(0)

        End If

        Dim serverName As String
        Dim userID As String
        Dim password As String
        Dim newPassword As String

        serverName = args(1)

        If args.Length > 2
            userID = args(2)
        Else
            userID = ""
        End If
        If args.Length > 3
            password = args(3)
        Else
            password = ""
        End If

        If args.Length > 4
        newPassword = args(4)
        Else
            newPassword = ""
        End If

        '-----------------
        ' Logon to server
        '-----------------

        Dim network As ZosNetwork = new ZosNetwork()
        Dim server As ZosServer = network.Servers(serverName)

        If server Is Nothing Then

            Console.WriteLine("Server {0} not found", serverName)
            Environment.Exit(1)

        End If

        server.Logon(userID, password, newPassword)

        Console.WriteLine("User {0} logged onto {1}", userID, serverName)
        Catch e As Exception

            Console.WriteLine(e.Message)
            Console.WriteLine(e.TargetSite)

        End Try

    End Sub

End Module

JScript Example

...

/**********************************************************************
* JScript Example
*
* File Name: Logon.js
*
* Description: Logon to server. If userid and password not specified, user will be prompted.
*
* Usage: Logon <server> [<userid>] [<password>] [<newpassword>]
*
* Copyright ©2007, Serena Software. Licensed material. All rights reserved.
**********************************************************************/


import System;
import ZosApi;

try
{
    //////////////////////////////
    // Get command line arguments
    /////////////////////////////

    var args : String[] = Environment.GetCommandLineArgs();

    if (args.Length < 2)
    {
        Console.WriteLine("Usage: Logon <server> [<userid>] [<password>]
         [<newpassword>]");
        Environment.Exit(0);
    }
    var serverName : String;
    var userID : String;
    var password : String;
    var newPassword : String;

    serverName = args[1];

    if (args.Length > 2)
    {
        userID = args[2];
    }
    else
    {
        userID = "";
    }

    if (args.Length > 3)
    {
        password = args[3];
    }
    else
    {
        password = "";
    }
    if (args.Length > 4)
    {
        newPassword = args[4];
    }
    else
    {
        newPassword = "";
    }

...

...

    ///////////////////
    // Logon to server
    ///////////////////

    var network : ZosNetwork = new ZosNetwork();
    var server : ZosServer = network.Servers[serverName];

    if (server == null)
    {
        Console.WriteLine("Server {0} not found", serverName);
        Environment.Exit(1);
    }
    server.Logon(userID, password, newPassword);

    Console.WriteLine("User {0} logged onto {1}", userID, serverName);

}
catch (e : Exception)
{
    Console.WriteLine(e.Message);
    Console.WriteLine(e.TargetSite);
}
Back to top