Is it possible to check whether a Windows installation is Genuine or not programmatically?
Lets just say I want to check Windows 7 from C, C++, Java or Python.
this from CodeProject, in C++ ( Check for Windows Genuine in VC++ )
#include <slpublic.h>
#pragma comment(lib,"Slwga.lib")
bool IsWindowsGenuine()
{
GUID uid;
RPC_WSTR rpc=(RPC_WSTR)_T("55c92734-d682-4d71-983e-d6ec3f16059f");
UuidFromString(rpc,&uid);
SL_GENUINE_STATE state;
SLIsGenuineLocal(&uid,&state,NULL);
return state == SL_GENUINE_STATE::SL_GEN_STATE_IS_GENUINE;
}
From here: Here is a vbscript that does it
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colWPA = objWMIService.ExecQuery _
("Select * from Win32_WindowsProductActivation")
For Each objWPA in colWPA
Wscript.Echo "Activation Required: " & objWPA.ActivationRequired
Wscript.Echo "Description: " & objWPA.Description
Wscript.Echo "Product ID: " & objWPA.ProductID
Wscript.Echo "Remaining Evaluation Period: " & _
objWPA.RemainingEvaluationPeriod
Wscript.Echo "Remaining Grace Period: " & objWPA.RemainingGracePeriod
Wscript.Echo "Server Name: " & objWPA.ServerName
Next
The Java solution is to use Process to run the C++ or VBScript solution as a child process.
Related
I have taken state plane coordinates from a SQL Server table and populated an object with 100 concatenated strings that will serve as my input into a java application.
$key = Invoke-Sqlcmd -Query "SELECT DISTINCT CONCAT('spc,'<spcZone>,',',
<northing>,',',<easting>, ',',<units>,',',<inDatum>,',',<outDatum>) as
conversionString FROM <source table>;" -ServerInstance "<server>" -Database
"<database>"
The result will be 100 strings that look like this in an array:
spc,2402,173099.419,503626.812,m,NAD83(2011),NAD83(2011)
I then use NOAA's gtk java application and run through all 100 observations to be converted:
$result = FOREACH ($k in $key.conversionString)
{
java -Dparms="$k" -jar H:\gtk\jtransform_thin.jar
}
The returned output for one observations looks like this:
{
"ID":"1489004917960",
"nadconVersion":"5.0",
"srcLat":"40.0000000000",
"srcLatDms":"N400000.000000",
"srcLon":"-80.0000000000",
"srcLonDms":"W0800000.000000",
"destLat":"40.0000000000",
"destLatDms":"N400000.000000",
"destLon":"-80.0000000000",
"destLonDms":"W0800000.000000",
"sigLat":"0.000000",
"sigLon":"0.000000",
"srcEht":"100.000",
"destEht":"100.000",
"sigEht":"0.000",
"srcDatum":"NAD83(1986)",
"destDatum":"NAD83(1986)",
"spcZone":"PA S-3702",
"spcNorthing_m":76470.584,
"spcEasting_m":407886.482,
"spcNorthing_usft":250887.241,
"spcEasting_usft":1338207.566,
"spcNorthing_ift":250887.743,
"spcEasting_ift":1338210.243,
"spcConvergence":"-01 27 35.224524",
"spcScaleFactor":0.99999024,
"spcCombinedFactor":0.99997455,
"utmZone":"UTM Zone 17",
"utmNorthing":4428236.065,
"utmEasting":585360.462,
"utmConvergence":"00 38 34.174932",
"utmScaleFactor":0.9996897,
"utmCombinedFactor":0.99967402,
"x":849623.061,
"y":-4818451.818,
"z":4078049.851,
"usng":"17TNE8536028236"
}
The problem I'm encountering is accessing the stored $result object's returned fields. If I type $result. It will return all text from all 100 observations. If I type $result[1] I only get the ID of the first observation. If I type $result.ID I do not have anything returned.
This is where I am trying to get to:
$add = foreach ($r in $result)
{
"INSERT INTO SPCtoLatLong VALUES ('" + $r.spcZone + "','" +
$r.spcNorthing_usft + "','" + $r.spcEasting_usft + "','" + $r.srcLat + "','"
+ $r.srcLon + "','" + $r.srcDatum + "','" + $r.destDatum + "')" + $nl
}
I only have 2 weeks experience in PowerShell, what am I doing wrong? Thank you for any help.
Stdout from external applications is returned as a string array (one line = one enum). You would need to parse the return data into an object, or, if you're on PowerShell 5+, you can utilize the ConvertFrom-String to create templates for these objects and pass it output to it to be converted.
But! Based on how well-formed your data is, I would do the following:
$Expected = $Result | ConvertFrom-Json
PS C:\> $Expected.GetType()
PSCustomObject
I figured out to solve this problem you should add this to the java application execution component.
$result = FOREACH ($k in $key.conversionString)
{
java -Dparms="$k" -jar H:\gtk\jtransform_thin.jar | ConvertFrom-Json
}
im wondering if there is any other way to read out the TeamSpeak Channel Chat with java.
I know that you could use a lua plugin which opens tha java program with the messages as parameter.
The code for the Lua Plugin's event.lua file: (could be outdated)
local function onTextMessageEvent(serverConnectionHandlerID, targetMode, toID, fromID, fromName, fromUniqueIdentifier, message, ffIgnored)
print("Testmodule: onTextMessageEvent: " .. serverConnectionHandlerID .. " " .. targetMode .. " " .. toID .. " " .. fromID .. " " .. fromName .. " " .. fromUniqueIdentifier .. " " .. message .. " " .. ffIgnored)
if targetMode == 2 then
os.execute("Program.exe " .. '"' .. message .. '"')
if message == "!command#1" or message == "!command#2" or message == "!command#3" then
folder = os.getenv("APPDATA")
file = io.open(folder .. "/" .. "tmp.txt", "r")
tempfile = file:read("*all")
file:close()
os.remove(folder .. "/" .. "tmp.txt")
ts3.requestSendChannelTextMsg(serverConnectionHandlerID, tempfile, fromID)
end
end
return 0
end
Basicly the Program.exe creates the tmp.txt file and writes the specified (inside the Program.exe) answer to the file which is sent to the chat by the lua plugin.
Now i want to know if there is any way to get the messages directly with java (so that the lua plugin isn't needed anymore)
I'm thankful for any help
I found out that you can simply scan the channel & server chatlogs for new entrys.
The Logs can be found here:
%APPDATA%\Roaming\TS3Client\chats\<UniqueServerID>
Unfortunately i have no idea how the UniqueServerID is generated and where the private chatlogs can be found.
I have a tool what uses Perforce. When it merge a branch back to the parent, mark the project branch with checkout a text file, and submit it unchanged. This tool also use that text file, for read the actual build number. My problem is, a "/n" appeared in the text, and because it have to contain just numbers, it's a big problem.
Have anyone met this problem, or this can't caused by P4C?
Maybe important, I don't use P4JAVA here.
Please note that I'm debugging right now, and I'm not sure the problem is here, but at the moment this seems the most probable.
//<path> is a legit path, I just shortened the code here
commandSync = "p4 -d " + getPerforceRoot() + " sync " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean syncCommandResult = commandExecuter.runAndGetResults(commandSync);
//command executer that runs the command string in cmd
commandMark = "p4 -d " + getPerforceRoot() + " edit -c " + changelistNumber + " " + selectedDataBean.getP4Path() + "<path>/BuildNum.txt";
CommandResultBean markCommandResult = commandExecuter.runAndGetResults(commandMark);
commandSubmit = "p4 -d " + getPerforceRoot() + " submit -f submitunchanged -c " + changelistNumber;
CommandResultBean submitCommandResult = commandExecuter.runAndGetResults(commandSubmit);
My program currently gets a list of drives plugged into the computer with File.listRoots(). But, when I plug a camera or an MP3 player into the computer directly (instead of inserting the memory card), it's not listed, nor does it have a drive letter in Windows Explorer. For example, here's the location of my camera:
Computer\Canon PowerShot SD750\Removable storage
How can I also list cameras/other devices that do not have a drive letter? I assume this will require a JNI library of some sort, but I don't know for sure obviously.
Thanks!
P.S. Out of desperation, I did try to list the contents of Computer\; it didn't work of course.
Update: I found this question here: Portable Device Path on Windows ; that's exactly the problem I'm having, but there is no solution laid out there.
Java 7 has some promising looking classes in this area, like this one:
http://download.java.net/jdk7/docs/api/java/nio/file/FileSystem.html
Assuming that you need it to work on Java 6 as well, I would suggest running a shell script and parsing its output.
On Windows you could run mountvol, on Unix/MacOS X mount etc. Of course parsing the output would be somewhat tedious and you would have to worry about every OS your app runs on, but hey, at least... not sure what.... it works?
Here is some sample code which seems helpful on Windows:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Volume")
For Each objItem In colItems
WScript.Echo "Automount: " & objItem.Automount
WScript.Echo "Block Size: " & objItem.BlockSize
WScript.Echo "Capacity: " & objItem.Capacity
WScript.Echo "Caption: " & objItem.Caption
WScript.Echo "Compressed: " & objItem.Compressed
WScript.Echo "Device ID: " & objItem.DeviceID
WScript.Echo "Dirty Bit Set: " & objItem.DirtyBitSet
WScript.Echo "Drive Letter: " & objItem.DriveLetter
WScript.Echo "Drive Type: " & objItem.DriveType
WScript.Echo "File System: " & objItem.FileSystem
WScript.Echo "Free Space: " & objItem.FreeSpace
WScript.Echo "Indexing Enabled: " & objItem.IndexingEnabled
WScript.Echo "Label: " & objItem.Label
WScript.Echo "Maximum File Name Length: " & objItem.MaximumFileNameLength
WScript.Echo "Name: " & objItem.Name
WScript.Echo "Quotas Enabled: " & objItem.QuotasEnabled
WScript.Echo "Quotas Incomplete: " & objItem.QuotasIncomplete
WScript.Echo "Quotas Rebuilding: " & objItem.QuotasRebuilding
WScript.Echo "Serial Number: " & objItem.SerialNumber
WScript.Echo "Supports Disk Quotas: " & objItem.SupportsDiskQuotas
WScript.Echo "Supports File-Based Compression: " & _
objItem.SupportsFileBasedCompression
WScript.Echo
Next
Here is the output I got for my ebook reader:
Automount: True
Block Size: 4096
Capacity: 999120896
Caption: G:\
Compressed:
Device ID: \\?\Volume{8e3b4ce5-a124-11e0-9d2b-e30c5839642d}\
Dirty Bit Set: False
Drive Letter: G:
Drive Type: 2
File System: FAT32
Free Space: 663683072
Indexing Enabled:
Label: PocketBook9
Maximum File Name Length: 255
Name: G:\
Quotas Enabled:
Quotas Incomplete:
Quotas Rebuilding:
Serial Number: 1276177233
Supports Disk Quotas: False
Supports File-Based Compression: False
The solution to above problem using JMTP library on
http://code.google.com/p/jmtp/
Here is my code
package jmtp;
import be.derycke.pieter.com.COMException;
import be.derycke.pieter.com.Guid;
import java.io.*;
import java.math.BigInteger;
import jmtp.PortableDevice;
import jmtp.*;
public class Jmtp {
public static void main(String[] args) {
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
// Connect to my mp3-player
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects()) {
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject) {
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects()) {
//
// BigInteger bigInteger1 = new BigInteger("123456789");
// File file = new File("c:/JavaAppletSigningGuide.pdf");
// try {
// storage.addAudioObject(file, "jj", "jj", bigInteger1);
// } catch (Exception e) {
// //System.out.println("Exception e = " + e);
// }
//
System.out.println(o2.getOriginalFileName());
}
}
}
manager.getDevices()[0].close();
}
}
Donot forget add jmtp.dll files (that comes up with jmtp download) as a native library for more info see my answer on
http://stackoverflow.com/questions/12798530/including-native-library-in-netbeans
This may not be the answer you're looking for, but is assigning them to a drive letter not an option? You can usually manually do this with USB devices on Windows using My Computer > right-click > Manage > Storage.
It's possible that CaptureDeviceManager in JMF (java media framework) could help you but I kind of doubt it.
Maybe you can take a look at Morena Framework http://www.gnome.sk/Twain/jtp.htmlv (seems to be open source, but a little expensive; though there is a free evaluation version), it is for TWAIN compatible scanners/cameras (Windows/MAC) or SANE compatible (Linux or other unix flavor), to get a list of connected devices, you can do this:
import SK.gnome.morena.*;
import SK.gnome.twain.*;
public class Test
{
public static void main(String[] args) throws Exception
{
TwainSource[] sources=TwainManager.listSources();
if(sources == null) return;
for(int i = 0; i < sources.length; i++)
{
System.out.println("Twain source is: " + ts.toString());
}
}
}
Maybe that could help,if not I think maybe JMF is a possible solution.
I am starting into NSS and I managed to build it. The outcome was placed in a folder named dist and has several subfolders that contain several exe's dlls etc.
dist
/WINNT6.0_DBG.OBJ
/bin
/include
/lib
I am trying to try it but I am not sure what is the nssLibraryDirectory and nssSecmodDirectory .
For the nssLibraryDirectory should I copy everything in the dist in a single file and refer to it from nssLibraryDirectory? What about nssSecmodDirectory? I'm not sure how I am suppose to configure to start using sun's pkcs11.
For example this trivial:
String configName = "nss.cfg";
Provider p = new sun.security.pkcs11.SunPKCS11(configName );
Where nss.cfg is:
name = NSS
nssLibraryDirectory = E:\NSS\nss-3.12.4-with-nspr-4.8\mozilla\dist\WINNT6.0_DBG.OBJ\lib
nssDbMode = noDb
Gives exception
Caused by: java.io.IOException: The
specified module could not be found.
at
sun.security.pkcs11.Secmod.nssLoadLibrary(Native
Method)
nssLibraryDirectory should only contain the lib subdirectory.
Its also has to appear in PATH - either by modifying environment variable or specifying it in JVM parameters.
Some note from my hard trying.... I think it would help anyone who want to use NSS.
I tend to construct a String in Java code to know in which line the error occurs. I must say it's better because Eclipse can eliminate all String construction errors. Then you pay attention to values to fill in.
I use these code:
String config = "xxxxxxx" +
"xxxxxxx" +
"xxxxxxx" +
"\n";
provider = new SunPKCS11(new ByteArrayInputStream(config.getBytes()));
Security.insertProviderAt(provider, 1);
All flags for Provider config:
(from http://j7a.ru/_config_8java_source.html,
seems like openjdk 8 sun.security.pkcs11.Config.java.)
name=xxxxxx //some text, " must be escaped with \
library=/location/of/your/.so/or/.dll/file //not compatible with NSS mode, must be quoted if contains space, and if quoted, " must be escaped
description=
slot= //not compatible with NSS mode
slotListIndex= //not compatible with NSS mode
enableMechanisms=
disableMechanisms=
attributes=
handleStartupErrors=
insertionCheckInterval=
showInfo=true/false
keyStoreCompatibilityMode=
explicitCancel=
omitInitialize=
allowSingleThreadedModules=
functionList=
nssUseSecmod=true/false //not campatible with 'library'
nssLibraryDirectory= //not campatible with 'library'
nssSecmodDirectory= //not campatible with 'library'
nssModule=some text //not campatible with 'library'
nssDbMode=readWrite, readOnly, noDb //not campatible with 'library'
nssNetscapeDbWorkaround=true/false //not campatible with 'library'
nssArgs="name1='value1' name2='value2' name3='value3' ... " //not compatible with NSS mode
nssUseSecmodTrust=true/false
Examples of nssArgs=: (separated by space)
"nssArgs=\"configdir='" + NSS_JSS_Utils.getFireFoxProfilePath() + "' "
+ "certPrefix='' "
+ "keyPrefix='' "
+ "secmod='secmod.db' "
+ "flags='readOnly'\""
Some example of escaping in Java code:
String config = "name=\"NSS Module\"\n" +
"......" +
"\n";
If with space, must be quoted with " ". ' ' is not able to be used. Every " must be escaped with \.
Now, some real examples.
To use Firefox security modules via NSS:
String config = "name=\"NSS Module\"\n"
+ "attributes=compatibility\n"
+ "showInfo=true\n"
+ "allowSingleThreadedModules=true\n"
+ "nssLibraryDirectory=" + NSS_JSS_Utils.NSS_LIB_DIR + "\n"
+ "nssUseSecmod=true\n"
+ "nssSecmodDirectory=" + NSS_JSS_Utils.getFireFoxProfilePath();
To use libsoftokn3.so (I don't know what it's used for, but I see someone have used it like this with nssArgs):
String config = "library=" + NSS_JSS_Utils.NSS_LIB_DIR + "/libsoftokn3.so" + "\n"
+ "name=\"Soft Token\"\n";
+ "slot=2\n"
+ "attributes=compatibility\n"
+ "allowSingleThreadedModules=true\n"
+ "showInfo=true\n"
+ "nssArgs=\"configdir='" + NSS_JSS_Utils.getFireFoxProfilePath() + "' "
+ "certPrefix='' "
+ "keyPrefix='' "
+ "secmod='secmod.db' "
+ "flags='readOnly'\""
+ "\n";
NSS_JSS_Utils.NSS_LIB_DIR returns the directory where all the NSS library libs are. Sometimes they are installed by default(e.g., in my RedHat 7.2), but sometimes you must install them manually.
NSS_JSS_Utils.getFireFoxProfilePath() returns where your FireFox profile are located. If you use modutil shipped with NSS/NSPR, you can see your installed security modules are stored in the secmod.db in this folder. If you cannot find them, you may have taken the wrong file.
More info about how to fill these values:
NSS PKCS#11 Spec