Hi, all
I am now trying to create virtual hard disks to our hyper-v vms via j-Interop. I wrote the following codes to create corresponding vhds but failed.
public static void createFixedVHD(String path, long size) throws JIException
{
try {
IJIDispatch imageManagementService = getImageManagementService();
JIVariant[] tmp = imageManagementService.callMethodA("CreateFixedVirtualHardDisk",
new Object[] { new JIString(path), new Long(size), JIVariant.EMPTY_BYREF() });
int res = tmp[0].getObjectAsInt();
if (res == 0) {
System.out.println("Successfully created a fixed disk.");
} else {
// 4096 means that the method is executing asynchronously (in
// the background) and you need to check
// its Job object to see when it’s finished and if it was successful
if (res == 4096) {
System.out.println("Creating fixed disk ...");
String jobPath = tmp[1].getObjectAsVariant().getObjectAsString2();
monitorJobState(jobPath, imageManagementService);
} else {
System.out.println("Error occurred while creating fixed disk.");
System.exit(1);
}
}
} catch (JIException e) {
System.out.println(e.getErrorCode());
System.out.println(e.getMessage());
}
}
To create dynamic vhds I replace "CreateFixedVirtualHardDisk" with "CreateDynamicVirtualHardDisk", the definition of CreateFixedVirtualHardDisk is below:
uint32 CreateFixedVirtualHardDisk(
[in] string Path,
[in] uint64 MaxInternalSize,
[out] CIM_ConcreteJob REF Job
);
When I called this function using
createFixedVHD("D:\\VirtualHardDisks\\New Virtual Hard Disk_2.vhdx", 100*1024*1024*1024),
an exception is captured like:
-2147352570
Unknown name. [0x80020006]
Can anybody help me? Thanks.
Last edit: Eric Song 2016-06-30
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This exception means that the COM server does not recognize the function
name you sent as a a valid function within its implementation. Does this
function actually exist ?
Hi, all
I am now trying to create virtual hard disks to our hyper-v vms via
j-Interop. I wrote the following codes to create corresponding vhds but
failed.
public static void createFixedVHD(String path, long size) throws
JIException
{
try {
IJIDispatch imageManagementService = getImageManagementService();
JIVariant[] tmp =
imageManagementService.callMethodA("CreateFixedVirtualHardDisk",
new Object[] { new JIString(path), new Long(size), JIVariant.EMPTY_BYREF()
});
int res = tmp[0].getObjectAsInt();
if (res == 0) {
System.out.println("Successfully created a fixed disk.");
} else {
// 4096 means that the method is executing asynchronously (in
// the background) and you need to check
// its Job object to see when it’s finished and if it was
// successful
if (res == 4096) {
System.out.println("Creating fixed disk ...");
String jobPath = tmp[1].getObjectAsVariant().getObjectAsString2();
monitorJobState(jobPath, imageManagementService);
} else {
System.out.println("Error occurred while creating fixed disk.");
System.exit(1);
}
}
} catch (JIException e) {
System.out.println(e.getErrorCode());
System.out.println(e.getMessage());
}
}
To create dynamic vhds I replace "CreateFixedVirtualHardDisk" with "CreateDynamicVirtualHardDisk", the definition of CreateFixedVirtualHardDisk is below:
--
The Mind is a place of its own. It can make a heaven out of hell or a hell
out of heaven. Attitude is everything. No matter how adverse conditions
maybe, one has the capacity to turn things around by one's Determination,
Perseverance and Hardwork.
John Milton
(Paradise Lost)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I reread the Microsoft (link is listed below) about the defination of the Msvm_ImageManagementService class. This function CreateFixedVirtualHardDisk really exists. Do you mean that j-Interop does not support such call?
The Msvm_ImageManagementService class has these methods.
Method Description
CompactVirtualHardDisk
Compacts a dynamic virtual hard disk file. Compacting is the process of unallocating unused portions of the virtual hard disk.
ConvertVirtualHardDisk
Converts the type of an existing virtual hard disk.
CreateDifferencingVirtualHardDisk
Creates a differencing .vhd file.
CreateDynamicVirtualHardDisk
Creates a dynamically expanding virtual hard disk (.vhd) file.
CreateFixedVirtualHardDisk
Creates a fixed-sized .vhd file.
GetVirtualHardDiskInfo
Retrieves information about the virtual hard disk files.
.
.
.
I can successfully call the function GetVirtualHardDiskInfo via the codes though. Any possibility that I pass wrong parameters when calling this function? I am wondering what type to use as this function needs a uint64 as input para for disk size.
Hope for your reply. Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I reread the Microsoft (link is listed below) about the defination of the
Msvm_ImageManagementService class. This function CreateFixedVirtualHardDisk
really exists. Do you mean that j-Interop does not support such call?
The Msvm_ImageManagementService class has these methods.
Method Description
CompactVirtualHardDisk
Compacts a dynamic virtual hard disk file. Compacting is the process of
unallocating unused portions of the virtual hard disk.
ConvertVirtualHardDisk
Converts the type of an existing virtual hard disk.
CreateDifferencingVirtualHardDisk
Creates a differencing .vhd file.
CreateDynamicVirtualHardDisk
Creates a dynamically expanding virtual hard disk (.vhd) file.
CreateFixedVirtualHardDisk
Creates a fixed-sized .vhd file.
GetVirtualHardDiskInfo
Retrieves information about the virtual hard disk files.
.
.
.
I can successfully call the function GetVirtualHardDiskInfo via the codes
though. Any possibility that I pass wrong parameters when calling this
function? I am wondering what type to use as this function needs a uint64
as input para for disk size.
public static void createFixedVHD(String path, long size) throws JIException
{
try {
IJIDispatch imageManagementService = getImageManagementService();
JIVariant[] tmp = imageManagementService.callMethodA("CreateFixedVirtualHardDisk",
new Object[] { new JIString(path), new Long(size), JIVariant.EMPTY_BYREF() });
int res = tmp[0].getObjectAsInt();
if (res == 0) {
System.out.println("Successfully created a fixed disk.");
} else {
// 4096 means that the method is executing asynchronously (in
// the background) and you need to check
// it’s Job object to see when it’s finished and if it was
// successful
if (res == 4096) {
System.out.println("Creating fixed disk ...");
String jobPath = tmp[1].getObjectAsVariant().getObjectAsString2();
monitorJobState(jobPath, imageManagementService);
} else {
System.out.println("Error occurred while creating fixed disk.");
System.exit(1);
}
}
} catch (JIException e) {
System.out.println(e.getErrorCode());
System.out.println(e.getMessage());
}
}
The WMI defination of the CreateFixedVirtualHardDisk function is :
StringfilePath="C:\\Hyper-V\\VirtualDisks\\songe1_test\\Virtual Hard Disks\\songe1_test_vdisk_test.vhdx";longsize=100*1024*1024*1024L;createFixedVHD(filePath,size);
Thanks for your help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
public static void createFixedVHD(String path, long size) throws JIException
{
try {
IJIDispatch imageManagementService = getImageManagementService();
JIVariant[] tmp = imageManagementService.callMethodA("CreateFixedVirtualHardDisk",
new Object[] { new JIString(path), new Long(size), JIVariant.EMPTY_BYREF() });
int res = tmp[0].getObjectAsInt();
if (res == 0) {
System.out.println("Successfully created a fixed disk.");
} else {
// 4096 means that the method is executing asynchronously (in
// the background) and you need to check
// it’s Job object to see when it’s finished and if it was
// successful
if (res == 4096) {
System.out.println("Creating fixed disk ...");
String jobPath = tmp[1].getObjectAsVariant().getObjectAsString2();
monitorJobState(jobPath, imageManagementService);
} else {
System.out.println("Error occurred while creating fixed disk.");
System.exit(1);
}
}
} catch (JIException e) {
System.out.println(e.getErrorCode());
System.out.println(e.getMessage());
}
}
The WMI defination of the CreateFixedVirtualHardDisk function is :
--
The Mind is a place of its own. It can make a heaven out of hell or a hell
out of heaven. Attitude is everything. No matter how adverse conditions
maybe, one has the capacity to turn things around by one's Determination,
Perseverance and Hardwork.
John Milton
(Paradise Lost)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, all
I am now trying to create virtual hard disks to our hyper-v vms via j-Interop. I wrote the following codes to create corresponding vhds but failed.
public static void createFixedVHD(String path, long size) throws JIException
{
try {
IJIDispatch imageManagementService = getImageManagementService();
JIVariant[] tmp = imageManagementService.callMethodA("CreateFixedVirtualHardDisk",
new Object[] { new JIString(path), new Long(size), JIVariant.EMPTY_BYREF() });
Can anybody help me? Thanks.
Last edit: Eric Song 2016-06-30
Hi,
This exception means that the COM server does not recognize the function
name you sent as a a valid function within its implementation. Does this
function actually exist ?
thanks,
best regards,
Vikram
On Thu, Jun 30, 2016 at 12:59 PM, Eric Song songyangeric@users.sf.net
wrote:
--
The Mind is a place of its own. It can make a heaven out of hell or a hell
out of heaven. Attitude is everything. No matter how adverse conditions
maybe, one has the capacity to turn things around by one's Determination,
Perseverance and Hardwork.
John Milton
(Paradise Lost)
Thanks for your reply, Vikram.
I reread the Microsoft (link is listed below) about the defination of the Msvm_ImageManagementService class. This function CreateFixedVirtualHardDisk really exists. Do you mean that j-Interop does not support such call?
https://msdn.microsoft.com/en-us/library/cc136845(v=vs.85).aspx
The Msvm_ImageManagementService class has these methods.
Method Description
CompactVirtualHardDisk
Compacts a dynamic virtual hard disk file. Compacting is the process of unallocating unused portions of the virtual hard disk.
ConvertVirtualHardDisk
Converts the type of an existing virtual hard disk.
CreateDifferencingVirtualHardDisk
Creates a differencing .vhd file.
CreateDynamicVirtualHardDisk
Creates a dynamically expanding virtual hard disk (.vhd) file.
CreateFixedVirtualHardDisk
Creates a fixed-sized .vhd file.
GetVirtualHardDiskInfo
Retrieves information about the virtual hard disk files.
.
.
.
I can successfully call the function GetVirtualHardDiskInfo via the codes though. Any possibility that I pass wrong parameters when calling this function? I am wondering what type to use as this function needs a uint64 as input para for disk size.
Hope for your reply. Thanks.
Hi,
Can you show me the method signature and definition of
createFixedVHD("D:\VirtualHardDisks\New Virtual Hard Disk_2.vhdx",
10010241024*1024),
Thanks,
Best regards,
Vikram
On Jul 1, 2016 7:57 AM, "Eric Song" songyangeric@users.sf.net wrote:
The WMI defination of the CreateFixedVirtualHardDisk function is :
I call my function via :
Thanks for your help.
Hi,
This seems okay. Please use the IJIUnsigned interface instead of "new
Long(size)" as parameter.
thanks,
best regards,
Vikram
On Fri, Jul 1, 2016 at 11:43 AM, Eric Song songyangeric@users.sf.net
wrote:
--
The Mind is a place of its own. It can make a heaven out of hell or a hell
out of heaven. Attitude is everything. No matter how adverse conditions
maybe, one has the capacity to turn things around by one's Determination,
Perseverance and Hardwork.
John Milton
(Paradise Lost)