Saturday, July 23, 2016

Running Unix (Putty) from VBA



Inder writes:

Hi All,

Kindly help me in the below code. It is running but only when am switching between excel and putty server manually.

Sub Putty()

Dim TaskID As Long
Windows("auto.xlsb").Activate
Sheets("Sheet1").Select
Range("h15").Select

TaskID = Shell("C:\Program Files (x86)\Quest Software\PuTTY\PuTTY.exe duk2srv0256 -pw password", vbMaximizedFocus)

AppActivate TaskID, True

SendKeys "{ENTER}", True
SendKeys "{ENTER}", True
wait
wait
SendKeys "sh /cm/dev/saswork/Inder/CV_Daily_Check/inder.sh"
SendKeys "{ENTER}", True

MsgBox "process completed"
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

Public Sub wait()

Dim sttime, curtime
Dim tt As Integer
sttime = Timer
tt = 0
While tt < 1
curtime = Timer
tt = curtime - sttime
Wend

End Sub



  • Kara Hewett


    cmd ="C:\MyUtilities\plink.exe -pw PASSWORD USERNAME@IPADDRESS cat /dataops/profits/name.csv"Setfile = CreateObject("Scripting.FileSystemObject").CreateTextFile("c:\name.csv",True)  Setshell = CreateObject("WScript.Shell") Setc = WshShell.Exec(cmd)DoWhile oExec.Status =0IfNot oExec.StdOut.AtEndOfStream Then datafile.WriteLine oExec.StdOut.Readall EndIfLoop datafile.Close



  • Windows Communication Framework Services are not Posting

    http://www.pcreview.co.uk/threads/wcf-services-are-not-reponding-after-sometime.4070472/#post-14255825

    adl



    Hey,

    I have multiple interconnected WCF services are hosted on IIS. I am also using a Windows ServiceBus to communicate with WCF services.They do not respond to any request after sometime even though I can browse metadata in the browser. Any help is appreciated.

    Thanks in advance.

    Kara Hewett

    Implicitly, the issue is whether the WCF services are operational. You could check the services in Task Scheduler and ensure the "Started". Also the logs for Task Scheduler would identify any errors. Also you could ping if the servers are up.

    Thursday, July 14, 2016

    Error on SNMP Java Client Application

    Error on SNMP Java Client Application


    sreekandank
    P: 45

    sreekandank
    I have written the following SNMP client code to display the hardware information
    Expand|Select|Wrap|Line Numbers
    1. import java.io.IOException;
    2. import org.snmp4j.CommunityTarget;
    3. import org.snmp4j.PDU;
    4. import org.snmp4j.Snmp;
    5. import org.snmp4j.Target;
    6. import org.snmp4j.TransportMapping;
    7. import org.snmp4j.event.ResponseEvent;
    8. import org.snmp4j.mp.SnmpConstants;
    9. import org.snmp4j.smi.Address;
    10. import org.snmp4j.smi.GenericAddress;
    11. import org.snmp4j.smi.OID;
    12. import org.snmp4j.smi.OctetString;
    13. import org.snmp4j.smi.VariableBinding;
    14. import org.snmp4j.transport.DefaultUdpTransportMapping;
    15. public class SNMPManager
    16. {
    17.  Snmp snmp=null;
    18.  String address=null;
    19.  public SNMPManager(String add)
    20.  {
    21.   address=add;
    22.  }
    23.  public static void main(String[] args)throws IOException
    24.  {
    25.   SNMPManager client=new SNMPManager("udp:127.0.0.1/161");
    26.   client.start();
    27.   String sysDescr=client.getAsString(new OID(".1.3.6.1.2.1.1.1.0"));
    28.   System.out.println(sysDescr);
    29.  }
    30.  private void start()throws IOException
    31.  {
    32.   TransportMapping transport=new DefaultUdpTransportMapping();
    33.   snmp = new Snmp(transport);
    34.   transport.listen();
    35.  }
    36.  public String getAsString(OID oid)throws IOException
    37.  {
    38.   ResponseEvent event=get(new OID[]{oid});
    39.   return event.getResponse().get(0).getVariable().toString();
    40.  }
    41.  public ResponseEvent get(OID oids[])throws IOException
    42.  {
    43.   PDU pdu=new PDU();
    44.   for(OID oid:oids)
    45.   {
    46.    pdu.add(new VariableBinding(oid));
    47.   }
    48.   pdu.setType(PDU.GET);
    49.   ResponseEvent event=snmp.send(pdu, getTarget(),null);
    50.   if(event != null)
    51.   {
    52.    return event;
    53.   }
    54.   throw new RuntimeException("GET timed out");
    55.  }
    56.  private Target getTarget()
    57.  {
    58.   Address targetAddress=GenericAddress.parse(address);
    59.   CommunityTarget target=new CommunityTarget();
    60.   target.setCommunity(new OctetString("public"));
    61.   target.setAddress(targetAddress);
    62.   target.setRetries(2);
    63.   target.setTimeout(1500);
    64.   target.setVersion(SnmpConstants.version2c);
    65.   return target;
    66.  }
    67. }
    68.  
    When I run this program, that shows the exception as given below:

    Exception in thread "main" java.lang.NoClassDefFoundError: org/snmp4j/TransportMapping
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.ja va:2442)
    at java.lang.Class.getMethod0(Class.java:2685)
    at java.lang.Class.getMethod(Class.java:1620)
    at sun.launcher.LauncherHelper.getMainMethod(Launcher Helper.java:494)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:486)

    Caused by: java.lang.ClassNotFoundException: org.snmp4j.TransportMapping
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 23)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 56)
    ... 6 more


    Please help me to correct this error. Thanks in advance... 

    Kara Hewett
    Did you add the jar SNMP4J to WEB-INF/lib?

    How to End Process Using Java

    How to end process using Java?




    P: 1

    rawash
    I am able to fetch all the processes which are running in Windows task Manager. Now I want to end a particular process from those processes. Is it possible in Java, or do i need to write some native code??
    Oct 9 '09 #1

    Kara Hewett

    You can also use Task Scheduler on a Windows Server and kill any java program which is running on that server.